question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to run job depending on other any job success?

See original GitHub issue

I need to run current job based on previous jobs.Which means if I have 2jobs before current job , I need to run current job if any one job is triggered/success. I tried needs event by putting 2 jobs inside.but it is running current job only if 2 jobs got success. Basically I’m expecting or functionality. Any solution?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

71reactions
fhammerlcommented, Aug 10, 2021

Try this example workflow. You can use always() to trigger a job regardless of other jobs failing. Then, in your job that has dependencies, you can set its run condition to if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}.

name: Run job if any dependency succeeds
on:
  push:
    branches: [ main ]
jobs:
  dep1:
    runs-on: ubuntu-latest
    steps:
      - name: Run FAILING script
        run: exit 1 
  dep2:
    runs-on: ubuntu-latest
    steps:
      - name: Run SUCCESS script
        run: echo Success
  job:
    runs-on: ubuntu-latest
    if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
    needs: [dep1, dep2]
    steps:
      - name: Hello World        
        env:
          NEEDS: ${{ toJSON(needs) }}     
        run: |
          echo "$NEEDS"
  nextjob:
    runs-on: ubuntu-latest
    if: ${{ always() }}
    needs: [job]
    steps:
      - name: Hello World        
        env:
          NEEDS: ${{ toJSON(needs) }}     
        run: |
          echo "$NEEDS"

Please note that if you ever add continue-on-error: true to the failing job dep1, it will set its result to success, so needs.dep1.result will always be success, thus rendering the check in job useless.

1reaction
PavelYatskevichcommented, Jul 27, 2023

Saved my day!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to put conditional job in need of another job in Github ...
jobs : A: runs-on: ubuntu-latest steps: - run: echo "success ... work since it will always be success for this job regardless did...
Read more >
How do i run a job based on success of another job?
The way I usually do that is to put the steps for the dependent jobs into the first job and set the "On...
Read more >
The basics of CI: How to run jobs sequentially, in parallel, ...
Every job contains a set of rules and instructions for GitLab CI, defined by special keywords. Jobs can run sequentially, in parallel, or...
Read more >
Conditions - Azure Pipelines
By default, a job or stage runs if it doesn't depend on any other job or stage, or if all of the jobs...
Read more >
7 advanced workflow automation features with GitHub ...
GitHub Actions runs multiple commands at the same time by default—but you can leverage the needs keyword to create dependencies between jobs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found