最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use a variable in a GitHub action step 'name'? - Stack Overflow

programmeradmin2浏览0评论

Given a GitHub workflow that looks something like this:

name: Test variable usage
on:
  workflow_dispatch:
env:
  STEP_NAME_01  : "Say hello"
  FRIENDLY_NAME : Joan
  HELLO_VERSION : develop
jobs:
  execute-hello-action-job:
    name: execute-hello-action-job
    runs-on: ubuntu-latest
    steps:
      - name: ${{STEP_NAME_01}}  ## <<--- This is where I would like to use a variable 
        uses: github/no_repository_provided/hello-world@develop
        with:
          friendly_name: ${FRIENDLY_NAME}

Is there a syntax that would let me supply the name of the step as a variable?

Given a GitHub workflow that looks something like this:

name: Test variable usage
on:
  workflow_dispatch:
env:
  STEP_NAME_01  : "Say hello"
  FRIENDLY_NAME : Joan
  HELLO_VERSION : develop
jobs:
  execute-hello-action-job:
    name: execute-hello-action-job
    runs-on: ubuntu-latest
    steps:
      - name: ${{STEP_NAME_01}}  ## <<--- This is where I would like to use a variable 
        uses: github/no_repository_provided/hello-world@develop
        with:
          friendly_name: ${FRIENDLY_NAME}

Is there a syntax that would let me supply the name of the step as a variable?

Share Improve this question edited Mar 15 at 3:05 hakre 198k55 gold badges449 silver badges856 bronze badges asked Mar 14 at 22:09 vscodervscoder 1,0411 gold badge14 silver badges33 bronze badges 2
  • Check this table: for the name value, the available contexts are github, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputs. What value do you want to supply? – Benjamin W. Commented Mar 15 at 2:57
  • Oh, I see, you provide is as an environment variable. Yes, you can do that, I'll add an answer. – Benjamin W. Commented Mar 15 at 2:57
Add a comment  | 

1 Answer 1

Reset to default 2

There's a handy table in the documentation showing which context is available where. For jobs.<job_id>.steps.name, the contexts are github, needs, strategy, matrix, job, runner, env, vars, secrets, steps, inputs.

In your case, you want to use a workflow-level environment variable. Those are accessible via the env context:

    steps:
      - name: ${{ env.STEP_NAME_01 }}
        uses: github/no_repository_provided/hello-world@develop
        with:
          friendly_name: ${{ env.FRIENDLY_NAME }}
发布评论

评论列表(0)

  1. 暂无评论