Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Action Set $GITHUB_ENV Not Saving

Per the documentation found here, I have tried setting a GitHub Action environment variable but noticed that the env variables don't seem to save. Has this been deprecated or is the documentation / my implementation just incorrect?

- name: Get Gradle VersionName
  working-directory : ${{ github.workspace }}/app
  run : |
    echo "Get Gradle VersionName"
    echo "action_state=yellow" >> $GITHUB_ENV
    echo "${{ env.action_state }}"
    grep 'versionName' build.gradle | awk '{print $2}'

enter image description here

like image 825
Pie Avatar asked Jun 04 '26 23:06

Pie


1 Answers

This behaviour is expected since "the step that creates or updates the environment variable does not have access to the new value, but all subsequent steps in a job will have access." (documentation)

To illustrate, consider the following definition of steps:

steps:
   - name: Step 1
     run: |
        echo "action_state=yellow" >> $GITHUB_ENV
        echo "State is: '${{ env.action_state }}'" # No output since same step
   - name: Step 2
     run: |
        echo "State is: '${{ env.action_state }}'" # Output works

Which results in this output:

result

like image 66
Matt Avatar answered Jun 07 '26 22:06

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!