I have a step that sets variables in the script section and gets accessed in the after-script section. However I have found that variables set in the script block are not available in the after-script block. I have read that both the blocks are run in the same container. Environment variables are accessible in both blocks.
Is it just not possible or am doing something wrong?
Here's an example:
Hi @Pavan Prasad and welcome to the community!
This is expected behavior. Both blocks indeed run on the same container. However, Pipelines creates a script with all commands of your step's script and runs it. Then, it creates a new script with all the commands of your step's after-script, and runs it in a new session. Therefore, any variables created during the script will not be available in the after-script.
As a workaround, you can save the export command in a file and then source the file in the after-script.
We have a feature request for defining variables per step in the yml file (this, making them available to the after-script) that you can vote for here:
Please feel free to reach out if you have any questions.
Kind regards,
Theodora
Thank you for your response, @Theodora Boudale. I am really looking forward to this feature being implemented. It will help make our pipeline more dynamic and simpler.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are very welcome, and thank you for the feedback; I see that you also left a comment on the feature request. When there is an update, it is going to be posted in that feature reuqest.
Please feel free to reach out if you ever need anything else!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.