6
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?

4
  • 1
    Would it be an option to use the job_id (in your car my-name) instead of the job name? Because the job_id is available in the Github Context using ${{ github.job }} when the job name is not...
    – GuiFalourd
    Commented Oct 20, 2021 at 0:46
  • 1
    @GuiFalourd Sorry, but no. Commented Oct 20, 2021 at 2:04
  • @DanielKaplan were you able to find a way to get the "My Name" value? Commented Sep 9, 2023 at 8:23
  • 1
    @MikalaiDaronin No, I used sorin's answer. Commented Sep 11, 2023 at 1:53

1 Answer 1

1

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.