How do I pass the job name into a github action's input?

Viewed 637
jobs:
  my-name:
    name: "My Name"
    ...
    steps:
      - name: Slack Notification
        uses: my-action
        with:
          slack-msg: ${{ jobs.${{ env.GITHUB_JOB }}.name }}

I want that slack-msg to evaluate to "My Name". I'm using my-action in multiple jobs, and I always want to pass in the job name, but I don't know how to do that. When I tried the above, the job literally didn't run and I don't know how to troubleshoot why: the github workflow log for my-name literally doesn't exist.

How do I pass job-name into an input parameter?

1 Answers

As nested expression are not supported you can use a trick like below to obtaint the matrix job name.

jobs:
  test:
    env:
      # to expose matrix job name to steps, which is not possible with expansions
      JOB_NAME: ${{ matrix.name || format('{0} ({1})', matrix.tox-target, matrix.os) }}
    name: ${{ matrix.name || format('{0} ({1})', matrix.tox-target, matrix.os) }}

Note that you cannot really access the matrix name, but you can ensure you save the same name into an environment variable and use that.

Related