-
Notifications
You must be signed in to change notification settings - Fork 181
Use current deployment context in SCRIPT_RUN stage #4814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We look forward to this feature! In our use case, we want to get the |
@minhquang4334 @peaceiris We can realize it by adding the default environment variable for
|
LGTM ʕ◔ϖ◔ʔ |
LGTM 🐳 @ffjlabo |
Thanks, both 👍 I will try it. Also, I received a comment from @khanhtc1202 about the implementation. So at first, I will investigate it :) |
After the investigation, I found out the way is possible. 👍 I will implement it later. Detail
Proceses usually have their own environment variable and separate them. Also, I tested the behavior using the code below, and it works as I expected. package main
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"golang.org/x/sync/errgroup"
)
func main() {
// This example shows that each exec.Cmd doesn't share the env value.
// Scenario:
// When executing "echo $DEPLOYMENT_ID" asynchronously with two exec.Cmd,
// The one is executed after 10s with "sleep 10", the other without any waiting time.
// Result:
// The output of the first command is "one" and the second is "two". Not shared.
/*
% go run main.go
===== D2 ======
output: two
err:
===== D1 (execute after 5s) ======
output: one
err:
*/
eg, _ := errgroup.WithContext(context.TODO())
eg.Go(func() error {
var outBuf, errBuf bytes.Buffer
cmd := exec.Command("/bin/sh", "-l", "-c", "sleep 5 && echo $DEPLOYMENT_ID")
cmd.Env = append(os.Environ(), "DEPLOYMENT_ID=one")
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
if err := cmd.Run(); err != nil {
return err
}
fmt.Println("===== D1 (execute after 5s) ======")
fmt.Println("output:", outBuf.String())
fmt.Println("err:", errBuf.String())
return nil
})
eg.Go(func() error {
var outBuf, errBuf bytes.Buffer
cmd := exec.Command("/bin/sh", "-l", "-c", "echo $DEPLOYMENT_ID")
cmd.Env = append(os.Environ(), "DEPLOYMENT_ID=two")
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
if err := cmd.Run(); err != nil {
return err
}
fmt.Println("===== D2 ======")
fmt.Println("output:", outBuf.String())
fmt.Println("err:", errBuf.String())
return nil
})
if err := eg.Wait(); err != nil {
fmt.Printf("error :%v\n", err)
}
} |
What would you like to be added:
Use current deployment context (like DeploymentTrigger, DeploymentStatus, etc.) in SCRIPT_RUN stage.
refs: https://pipecd.dev/docs-v0.46.x/user-guide/managing-application/customizing-deployment/script-run/
Why is this needed:
Since we don't know about the current deployment, it is difficult to write a script for customization of the deployment process.
This is similar to GitHubAction, where we can access job and step contexts through a defined property.
refs: https://docs.github.com/en/actions/learn-github-actions/contexts#job-context
The text was updated successfully, but these errors were encountered: