how to set action env variables within a shell script?

I’ve got a bash script that forms a bunch of env variables used to tag build artifacts.

How do I export these variables from the shell script into the action build variables?


actually running 

echo “::set-env name=VERSION_TAG::$VERSION_TAG”

within the shell script does does translate into an action variable.

I’ve built a test bed that does work :slight_smile:

Hi @andy-brainome , 

The set-env command will add environment variable to all the following steps in the current job. 

action env.png

What’s your meaning of “action build variables” ? If you want to use the env in action’s input under with section, you could use 

${{ env.VERSION_TAG }} to get the value of it. For example: 

- name: Create Release
      id: create_release
      uses: actions/create-release@latest
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
        tag_name: ${{ env.VERSION_TAG }}

My issue is with exporting env variables from within a shell script into action env variables.

I tried using the echo “::set-env…”  from within the shell script without success - I suspect ::set-env does not trigger the action from registering env variables

pseudocode e.g.

export VERSION=19.2.5
export FULL_TAG=19.2.5-beta
export SHORT_TAG=beta


- name: calc version
   run: ./ 

- name: build and push myimage
   run: |
     docker build -t myimage:${{ env. FULL_TAG }} .
     docker push myimage:${{ env.FULL_TAG }}
     docker tag myimage:${{ env. FULL_TAG }} myimage:${{ env.SHORT_TAG }}
     docker push myimage:${{ env.SHORT_TAG }}

You should access your env vars like this

docker build -t myimage:${FULL_TAG} .

docker build -t myimage:$FULL_TAG .

I guess that run command executes as is. So double curly braces isn’t a valid syntax for shell command, at least to access env variable. The two variants above are valid.

I think that the following syntax ${{ env. FULL_TAG }} it’s a way to access variables in the YAML context. For example, pass arguments to actions.

I tried add set-env command in bash scripts : 

echo "::set-env name=VERSION::19.2.5"

My workflow is : 

    runs-on: ubuntu-latest
    - uses: actions/checkout@v2
    - name: set output
      id: set
      run: |

       chmod +x

    - name: use output
      run: |
        echo $VERSION
        echo ${{env.VERSION }}

Both invoke env variable syntax could work: 

VERSION&nbsp; and&nbsp;{{env.VERSION }}

Can you try again?