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?

(EDITED)

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:

https://github.com/astevko/action-test

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
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
      with:
        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.

calc-version.sh

#!/bin/bash
export VERSION=19.2.5
export FULL_TAG=19.2.5-beta
export SHORT_TAG=beta

build-docker.yml

<snip>
- name: calc version
   run: ./calc-version.sh 

- 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 calc-version.sh : 

#!/bin/bash
echo "::set-env name=VERSION::19.2.5"

My workflow is : 

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

       chmod +x calc-version.sh
       ./calc-version.sh

    - 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?