Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Job is not found" message appearing in job and took fields #185

Open
phr3nzii opened this issue Jan 14, 2022 · 5 comments
Open

"Job is not found" message appearing in job and took fields #185

phr3nzii opened this issue Jan 14, 2022 · 5 comments

Comments

@phr3nzii
Copy link

Describe the bug
When trying to output the job name and time taken in a Slack message I am getting a "Job is not found" message. However, if I overwrite the job name then the details are successfully populated.

To Reproduce
This is the GitHub Actions config that I have used:

name: Slack Test Workflow

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  slack_test:
    name: Slack Test Job
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.4.0
      - name: Hello
        run: echo "Hello!"
      - name: Slack Notification
        uses: 8398a7/action-slack@v3.13.0
        with:
          status: ${{ job.status }}
          fields: repo,job,commit,workflow,took,pullRequest
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: always()

If you add

job_name: Slack Test Job

to the with section then the job and took fields are populated correctly on the Slack message.

Expected behavior
My understanding is that the job name should automatically be detected, which would then mean that the job and took fields are successfully populated. If that is correct then I would expect those fields to be successfully populated without having to specify the job name.

Screenshots
image

@mbonig
Copy link

mbonig commented Apr 5, 2022

Having a similar issue when trying to use a custom message:

     - uses: 8398a7/action-slack@v3
        with:
          status: custom
          fields: job,repo,message,commit,author,action,pullRequest,workflow,took
          custom_payload: |
            {
              attachments: [{
                color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
                text: `${process.env.AS_REPO} :: ${process.env.AS_WORKFLOW} - QA1\n(${process.env.AS_PULL_REQUEST}) by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
              }]
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
        if: always() # Pick up events even if the job fails or is canceled.

results in:
Screen Shot 2022-04-05 at 9 15 37 AM

@goonzoid
Copy link

I had a similar problem. My current belief is that the docs here: https://action-slack.netlify.app/with#job_name are poorly worded, but are actually intended to imply that you must specify the job_name and have it match the actual name of the job, in order for things like took to work.

@hwood-fg
Copy link
Contributor

I had a similar problem. My current belief is that the docs here: https://action-slack.netlify.app/with#job_name are poorly worded...

Updated link: https://action-slack.netlify.app/usage/with/

@mywristbands
Copy link

mywristbands commented Jul 19, 2023

I had a similar problem. My current belief is that the docs here: https://action-slack.netlify.app/with#job_name are poorly worded...

Yes, it appears you must either specify the actual job name for the job_name field, or you can omit the job_name and then it will infer the job name for you. So you might as well just omit the job_name field!

@bertrandoubida
Copy link

bertrandoubida commented Dec 7, 2023

So what would it look like in the original case of the first person that asked the question? Would it be "fields: repo,slack_test,commit,workflow,took,pullRequest" ? Can someone edit the to reproduce the full code to show us. is the code below correct?

name: Slack Test Workflow

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  slack_test:
    name: Slack Test Job
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2.4.0
      - name: Hello
        run: echo "Hello!"
      - name: Slack Notification
        uses: 8398a7/action-slack@v3.13.0
        with:
          status: ${{ job.status }}
          fields: repo,slack_test,commit,workflow,took,pullRequest
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: always()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants