In Gitlab-CI, you can use after_script
to do some stuff after a job, what ever appends during the job.
Issue
But if you tried to share environment variables from your before_script
or script
part (note : I talk about environment variables which are declared with export
in one of this section), you won't be able to access to them.
What cause the issue?
For the after_script
execution, Gitlab will create a new shell instancce to execute it.
So all the temporary elements which are not shared accross multiple shell instances won't be accessible in after_script
.
Resolution
So to resolve it, you can just print the value of the desired environment variable in a file, then read this file in the after_script
section.
job:
before_script:
- export TEST="test"
- echo $TEST > test
after_script:
- export TEST = $(cat test)
- echo $TEST
Links
- Gitlab : https://gitlab.com/
- Gitlab-CI - after_script : https://docs.gitlab.com/ee/ci/yaml/#after_script
I hope it will help you! 🍺
Top comments (0)