Assigning shell value to environment variable?

I am needing to set an environment variable based on an execution of shell script, but I haven’t been able to get it to work.

      - name: Setup versions
        run: export VERSION=99.99.99; DATE=`date +%Y%m%d`

values aren’t listed in the env in the next step.

I did also try:

  VERSION: 99.99.99
   DATE: `date +%Y%m%d`

but that is invalid syntax per YAML.

Any suggestions?

Each run step gets its own shell instance, so exported variables don’t carry over. If you want that, you need to write to the GITHUB_ENV environment file, e.g.:

- name: Setup versions
  run: |
    echo "VERSION=99.99.99" >>${GITHUB_ENV}
    echo "DATE=$(date +%Y%m%d)" >>${GITHUB_ENV}

The VERSION and DATE environment variables will be available in all subsequent steps of the job.

For details, see Setting an environment variable.

1 Like