Home > Back-end >  add variable value to github action name
add variable value to github action name

Time:10-26

How do I create a github workflow step name with a variable value.

I tried this but it does not work.

name: Publish
on:
  push:
    branches:
      - main
env:
  REGISTRY: ghcr.io

jobs:
  Publish:
    runs-on: ubuntu-latest
    steps:
      - name: Log into Container registry ${{ env.REGISTRY }}

CodePudding user response:

I know you tried it, but reproducing the workflow evidence

CodePudding user response:

Since this does not seem supported, it is better to add an echo which prints the variable, before one processing it:

name: Publish
on:
  push:
    branches:
      - main
env:
  REGISTRY: ghcr.io

jobs:
  Publish:
    runs-on: ubuntu-latest
    steps:
      - name: Log into Container registry 
        run: echo "registry is '$REGISTRY'"

After that, for runtime variables, you can add conditions:

on:
  push:
    branches:
      - actions-test-branch

jobs:
  Echo-On-Commit:
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout Repository"
        uses: actions/checkout@v2

      - name: "Set flag from Commit"
        env:
          COMMIT_VAR: ${{ contains(github.event.head_commit.message, '[commit var]') }}
        run: |
          if ${COMMIT_VAR} == true; then
            echo "flag=true" >> $GITHUB_ENV
            echo "flag set to true"
          else
            echo "flag=false" >> $GITHUB_ENV
            echo "flag set to false"
          fi

      - name: "Use flag if true"
        if: env.flag
        run: echo "Flag is available and true"
  • Related