Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github action jobs triggered by different events

My release pipeline in Github action has two jobs (1) Testing (2) Release

This is what I am aim to achieve:

The testing job of the release pipeline will be triggered by creating a pull-request, the release job of the pipeline will be rung when pull-request is merged

name: OC-API CD
on: 
  pull_request:
    types: [merged]
    branches: 
       - master

jobs:
  testing:
  runs-on: ubuntu-latest
  steps:
  ...

  release:
  runs-on: ubuntu-latest
  steps:
  ...

It seems all jobs has to be triggered by the same events via on,

(1) Is there any way that different job can be triggered by different events?

(2) How can I add dependency between testing and release, AKA, the release job is depend on the successfully runs the testing job

like image 843
SLN Avatar asked Sep 14 '25 21:09

SLN


1 Answers

You can control each job by adding if, in your case it will be like this:

jobs:
  testing:
  if: ${{ github.event.action }} == 'opened'
  runs-on: ubuntu-latest
  steps:
  ...

Keep in mind you have to add opened to a on: pull_request: types: array of course :)

For the second part you can add dependency using needs, like this:


jobs:
  testing:
  runs-on: ubuntu-latest
  steps:
  ...

  release:
  needs: testing
  runs-on: ubuntu-latest
  steps:
  ...
like image 186
Grzegorz Krukowski Avatar answered Sep 17 '25 18:09

Grzegorz Krukowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!