Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

Workflow is failing if no job can be ran due to condition

Solved! Go to Solution.

I'm trying to avoid one job to run conditionnally. For instance, let's say I want to control a "/rebase" command to only trigger the rebase job steps on PR:

on:
  issue_comment:
    types: [created]

name: PR commands
jobs:
  rebase:
    name: Rebase
    if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Automatic Rebase
      uses: cirrus-actions/rebase@1.2
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The issue is that the workflow will exit in error (and so, send failure emails). In the Action UI, clicking on it will redirect to the previous running workflow of another type.

 

One workaround right now is to let the job starting, and duplicate the condition on each step:

on:
  issue_comment:
    types: [created]

name: PR commands
jobs:
  rebase:
    name: Rebase
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
      if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
    - name: Automatic Rebase
      uses: cirrus-actions/rebase@1.2
      if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Is there any way to completely prevent the job to start, and thus, avoiding the cirrus-actions/rebase@1.2 docker image action build?

1 Reply
Solution
GitHub Partner
Message 2 of 2

Re: Workflow is failing if no job can be ran due to condition

Hi @didrocks ,

 

In the past, if all jobs in a workflow were skipped with the conditions, the workflow will display as "skipped/no status" status with a grey icon. But now, it displays as failed status.

I had reported this issue to the appropriate engineering team, and the team has began to investigate it.
Currently, we don't have any other ways to skip the jobs. However, as a workaround, you can add a job to always run in the workflow, you do not need to add any usable steps in this job, and just execute a line of script that don't make sense. At this situation, when all other jobs are skipped with the if condition, the workflow will not be failed status.

workaround.PNG