skip to Main Content

In the beginning of a (re-usable) workflow

env:
  STAGING_GCR_PROJECT: my-project-id

and when using it

  slack_staging_success:
    needs: build_staging
    runs-on: ubuntu-latest
    if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
    env:
      STAGING_IMAGE: "gcr.io/$STAGING_GCR_PROJECT/${{ inputs.image_name }}:${{ inputs.image_tag }}"

    
    steps:
      
    - name: slack success for staging
      uses: rtCamp/action-slack-notify@v2
      env:
        SLACK_ICON: $SLACK_ICON_SUCCESS
        SLACK_COLOR: green
        SLACK_MESSAGE: "STAGING image ${{ env.STAGING_IMAGE }} was built / pushed with SUCCESS"

In Slack the message interpolates as

STAGING image gcr.io/$STAGING_GCR_PROJECT/echo-server:1.0.2 failed to be built

Why isn’t $STAGING_GCR_PROJECT interpolated correctly?

2

Answers


  1. In order to use workflow environment variables, use the prefix env. and enclose it in ${{ }} just like you did with the inputs:

    env:
      STAGING_IMAGE: "gcr.io/${{ env.STAGING_GCR_PROJECT }}/${{ inputs.image_name }}:${{ inputs.image_tag }}"
    
    Login or Signup to reply.
  2. It is not supported at the moment, to have env variable inside env.

    The docs on env mentions it:

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search