Parameter on step "if previous skipped"

In looking through the documentation, I don’t see anything like this exists, but asking for good measure. Is there a convenient “if” statement that can be added to a step which can take action based upon what the previous step did? For example, I’m using an if statement that points to a specific step, but what I’d like to do is something like:

if: steps.previous.conclusion == 'skipped'

So rather than pointing to a specific step’s id, I simply want to say “if the previous step was skipped, then also skip this one” that I could add to any subsequent steps I want skipped.

Hi @chipzoller ,

Github supports if expression, please check Job status check functions doc for more details.
Besides, typically we can also use set-output in previous step, and check the output value with if expression in next steps. code sample as below:

- name: setoutput
        id: job1output
        run: |
          echo "::set-output name=action_fruit::strawberry" # set output in step1
      - name: checkoutput
        if: steps.job1output.outputs.action_fruit == 'strawberry' # use if expression to check the output value.
        run: |
          echo execute this step!

There’s no expression/function to check previous step is skipped or not.

Hope it’s clear and helpful!

Yes, thanks, I’m aware of that and that is what I’m currently implementing. However, the problem with this is I have to reference this one step in all other steps by ID. If that ID should change, all the subsequent steps have to be changed. I’m simply wondering if there’s an easier way than hard referencing a specific steps ID. I’m guessing there isn’t.

Hi @chipzoller ,

Thanks for your quick reply! Yes, for ‘set-ouput’, you have to reference the step ID for the output value.

After further investigation, the step state can be got from step context, still need to add ID for the previous step, and get step state from ${{ steps.ID.conclusion }} or ${{ steps.ID.outcome }}. Code sample as below:

- name: skip this step
<font color="#FF6600">id: test</font># add step ID here
        if: .... # skip this step
        run: ...
      - name: check
<font color="#FF6600">if: steps.test.outcome == 'Skipped'</font># execute when test step is Skipped.
        run: |
          echo previous step is skipped

If you don’t want to use ID, you can use ‘set-env’, code sample as below:

- name: setenv
        run: |
          echo "::set-env name=action_state::yellow"
      - name: useenv
        if: env.action_state == 'yellow'
        run: |
          echo run this step # execute this step if value meets in expression.

Thanks.