Skip to content

Add instructions how to use status check outside if conditionals #39463

@arxeiss

Description

@arxeiss

Code of Conduct

What article on docs.github.com is affected?

Status check functions

What part(s) of the article would you like to see updated?

Status check functions can be used only inside conditionals ie if.

I would like to add info, how same information - success/failure/cancelled - can be accessed in inputs for action.

I have prepared PR with updating docs #39464

Additional information

We want to send Slack message when job succeed, but also fails. And we had 2 action steps with same setup, except the message. By coincidence I have found that you can use job.status too. But it is not mentioned in the Status check functions. So I simply thought it is not possible at all.

After my finding, I was able to convert this

- name: Slack Notification Success
  if: success()
  uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1 - https://github.com/slackapi/slack-github-action/releases
  with:
      token: ${{ secrets.SLACK_BOT_TOKEN }}
      method: chat.postMessage
      payload: |
          {
            "channel": "${{ secrets.SLACK_CHANNEL_FOR_DEPLOYMENT }}",
            "text": "✅ *${{ inputs.env-values-path }}:* deployed successfully",
            "thread_ts": "${{ inputs.slack_thread }}"
          }
- name: Slack Notification Failure
  if: failure()
  uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1 - https://github.com/slackapi/slack-github-action/releases
  with:
      token: ${{ secrets.SLACK_BOT_TOKEN }}
      method: chat.postMessage
      payload: |
          {
            "channel": "${{ secrets.SLACK_CHANNEL_FOR_DEPLOYMENT }}",
            "text": "❌ *${{ inputs.env-values-path }}:* deployment failed. Check the pipeline ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
            "thread_ts": "${{ inputs.slack_thread }}"
          }

into

- name: Slack Notification Success
  if: success() || failure()
  uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1 - https://github.com/slackapi/slack-github-action/releases
  with:
      token: ${{ secrets.SLACK_BOT_TOKEN }}
      method: chat.postMessage
      payload: |
          {
            "channel": "${{ secrets.SLACK_CHANNEL_FOR_DEPLOYMENT }}",
            "thread_ts": "${{ inputs.slack_thread }}",
            "text": "${{ job.status == 'success'
                && format(':white_check_mark: *{0}:* deployed successfully', inputs.env-values-path)
                || format(':x: *{0}:* deployment failed. Check the pipeline {1}/{2}/actions/runs/{3}', inputs.env-values-path, github.server_url, github.repository, github.run_id)
            }}"
          }

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentThis issue or pull request belongs to the Docs Content teamgithub_actionsPull requests that update GitHub Actions code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions