Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read environment variables in env section of github action workflow

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:
  1. The example for BASE_VERSION above just keeps ${BASE_VERSION} as a string
  2. $BASE_VERSION also just keeps $BASE_VERSION as a string
  3. ${{ env.BASE_VERSION }}-blabla just fails with syntax error

Is this doable?

The output I want is "1.0.0-1-master" for example

like image 951
Mark Avatar asked Nov 28 '25 14:11

Mark


2 Answers

Is this doable?

It does not seem like a supported behaviour at the moment.

The docs on env mentions that

variables in the env map cannot be defined in terms of other variables in the map.

like image 141
lyzlisa Avatar answered Nov 30 '25 03:11

lyzlisa


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
like image 22
Stefano L Avatar answered Nov 30 '25 04:11

Stefano L



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!