Kay
Kay

Reputation: 19680

How to store and retrieve a value in different steps using github actions

I have a github pipeline, there is a job. I want to get a value in the later steps that was initially set in the first step.

jobs:
  backup:
    name: "Backup"
    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v2
    - name: Update Config 
      run: |
        export ORIGINAL_RDS_MAX_EXEC_TIME=123
    - name: Create DB Backup
      run: |
         // do some work
    - name: Cleanup
      if: always()
      run: |
        echo $ORIGINAL_RDS_MAX_EXEC_TIME // returns nothing
 

The echo in the final step of this job does not return anything, it seems like that original export variable is no longer present

Upvotes: 1

Views: 1099

Answers (1)

Benjamin W.
Benjamin W.

Reputation: 52162

You can set an output parameter and reference that later on:

    - name: Set output
      id: setter
      run: |
        echo "foo=bar" >> "$GITHUB_OUTPUT"

    - name: Use output
      run: |
        echo "${{ steps.setter.outputs.foo }}"

or you can add it to the environment:

    - name: Set environment variable
      run: |
        echo "FOO=bar" >> "$GITHUB_ENV"

    - name: Use environment variable
      run: |
        echo "$FOO"

Upvotes: 4

Related Questions