I have a workflow with 2 jobs. The first workflow must set an environment variable to some value, so that the value persists for access to the second job. But I could not figure out how to do that.
Here is an example of my situtation:
name: Play with environment variables # Set an environment variable with initial value env: TEST_RESULT: 'success' on: push: jobs: job-1: name: Change env variable runs-on: ubuntu-latest steps: - name: Print env variable run: echo 'TEST_RESULT is' $TEST_RESULT # prints 'TEST_RESULT is success' - name: Set env variable run: echo "::set-env name=TEST_RESULT::failure" - name: Print env variable run: echo 'TEST_RESULT is' $TEST_RESULT # prints 'TEST_RESULT is failure' job-2: name: Access modified env variable runs-on: ubuntu-latest needs: job-1 steps: - name: Print env variable run: echo 'TEST_RESULT is' $TEST_RESULT # prints 'TEST_RESULT is success'
So, I initially specified an environment variable TEST_RESULT, and set its value to ‘success’.
Then, in the first job (job-1) I first printed TEST_RESULT and saw it was indeed ‘success’. I then changed the value of TEST_RESULT to ‘failure’, and additionally printed its value after modification - final result of TEST_RESULT in job-1 was ‘failure’.
Then a second job (job-2) started. I also looked at the value of TEST_RESULT there, but the value was the original ‘success’ value.
So, is the a possibility to persist values of environment variables, so that subsequent jobs have access to updated values and not the original value?