Skip to content
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

feat: add SD_STEP_NAME env variable #439

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ func doRunSetupCommand(emitter screwdriver.Emitter, f *os.File, r io.Reader, set
return nil
}

func doRunCommand(guid, path string, emitter screwdriver.Emitter, f *os.File, fReader io.Reader) (int, error) {
func doRunCommand(guid, path string, emitter screwdriver.Emitter, f *os.File, fReader io.Reader, stepName string) (int, error) {
executionCommand := []string{
"export SD_STEP_ID=" + guid,
// escape not necessary because step name is limited to [A-Za-z0-9_-]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

";export SD_STEP_NAME=" + stepName,
";. " + path,
";echo",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to my change, but I noticed that the commit introducing this 'echo' statement (2556c79 / #109) unintentionally broke the status check on the next line ($? comes from echo rather than from source).

It shouldn't really make a difference (i.e. echo guid $? would be skipped because of set -e if the user code results in anything other than success). But it's not the original intent of the code (and confusing). It should either just be echo 0 (because we know the line will only ever be reached on success) or something like "; printf \\\\n " + guid + " $?\n" and the extraneous echo removed.

If you have a preferred fix among those options, I am happy to send a separate pr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, u can use that printf or echo, whichever can wrap a newline before and after will do

";echo " + guid + " $?\n",
Expand Down Expand Up @@ -336,7 +338,7 @@ func Run(path string, env []string, emitter screwdriver.Emitter, build screwdriv
fReader := bufio.NewReader(f)

go func() {
runCode, rcErr := doRunCommand(guid, stepFilePath, emitter, f, fReader)
runCode, rcErr := doRunCommand(guid, stepFilePath, emitter, f, fReader, cmd.Name)
// exit code & errors from doRunCommand
eCode <- runCode
runErr <- rcErr
Expand Down