Skip to content

How to get job.status into shell script? #25729

How to get job.status into shell script? #25729
Jan 13, 2022 · 3 answers

It should be really basic stuff but I couldn’t figure it out…
There is job.status context, and I want to use it in my shell script (in order to set a color for Slack notification). How can I get this job.status into script?

You need to provide it to the step in some way. Exactly how depends on how your script wants to consume that data. You could put it on the command line:

steps:
  - run: ./my_script.sh ${{ job.status }}

Or into the environment:

steps:
  - run: ./my_script.sh
    env:
      STATUS: ${{ job.status }}

Replies

3 suggested answers

You need to provide it to the step in some way. Exactly how depends on how your script wants to consume that data. You could put it on the command line:

steps:
  - run: ./my_script.sh ${{ job.status }}

Or into the environment:

steps:
  - run: ./my_script.sh
    env:
      STATUS: ${{ job.status }}
0 replies
Answer selected

Many thanks!
In fact, I asked the wrong question. I’m using Github action for Slack notification and I’d like to use the job status for setting Slack notification color. I don’t like to idea using separate steps for each job status, i.e. for success(), failure(), and so on.
I’m trying to use an expression for setting color param; without success so far.

 with:
      color: ${{ env.STATUS }} == 'success' && 'good' || 'bad'

Tried “color: failure() && ‘good’ || ‘bad’” and other variations - the same result.

0 replies

I figured it out - as usually RTFM helps.
Thank you again.

color: ${{ job.status == ‘success’ && ‘good’ || ‘bad’ }}

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants