Reputation: 5513
I'm trying to set a env variable based on another env variable in a github workflow. I've tried a couple of syntax options but none seem to work
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
env:
BASE_VERSION: 1.0.0
FULL_VERSION: ${BASE_VERSION}-${{ github.run_number }}-${{ github.ref_name }}
jobs:
Is this doable?
The output I want is "1.0.0-1-master" for example
Upvotes: 20
Views: 17457
Reputation: 139
As @lyzlisa stated, it does not work for env variable at the same level, but it does work if you reuse a top level env variable in a lower level env variable definition:
env:
SOME_GLOBAL_VAR: 1.0.0
jobs:
build:
name: My build
env:
SOME_BUILD_VAR: "${{ env.SOME_GLOBAL_VAR }}-build"
steps:
- name: My step
env:
SOME_STEP_VAR: "${{ env.SOME_GLOBAL_VAR }} ${{ env.SOME_BUILD_VAR}} step 1"
run:
...
Upvotes: 1
Reputation: 1593
Do it like this:
- name: Set docker image env var
run: |
echo "DOCKER_IMAGE=${ARTIFACTORY_URL}/${IMAGE_NAME}:${GITHUB_REF##*/}.${{github.run_number}}" >> $GITHUB_ENV
- run: |
echo ${{ env.DOCKER_IMAGE }}
Outputs
artifactory-host/some-project/some-repo/image-name:branch.number
Upvotes: 11