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

Conversation

jacobtolar
Copy link
Contributor

Context

As a user, I want to access the current step name from code executing within the step.

Objective

Add new environment variable SD_STEP_NAME set before each ordinary step is executed run. Only set for ordinary user steps, not setup or teardown commands (during teardown, SD_STEP_NAME would be set to the last successfully executed step). If desired I could change this behavior.

References

License

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

executionCommand := []string{
"export SD_STEP_ID=" + guid,
// escape not necessary because step name is limited to [A-Za-z0-9_-]
";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

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.

@tkyi tkyi merged commit b3c5435 into screwdriver-cd:master Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants