Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Action Trigger on multiple on: push: paths

In single repo, I want to create more than one trigger for different paths [paths: 'frontend/**' and paths: 'backend/**'] with different parameters for (same) build jobs. Following are the two workflow.

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 'frontend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
    - name: Trigger Build-Portal
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...

and

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
    - name: Trigger Build-Portal
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...

Can I combine these two in a single workflow file (.github/workflows/) or it need to have separate files for each ?

Note : job_params are different in for both triggers.

like image 641
roy Avatar asked Feb 23 '26 16:02

roy


2 Answers

According to the github action documentation, it should work in the same workflow using multiple paths.

If you also use the paths-filter action you can get to the result you want with something like this:

Example:

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 
       - 'frontend/**'
       - 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
      - uses: dorny/paths-filter@v2
        id: changes
        with:
           filters: |
              backend:
                - 'backend/**'
              frontend:
                - 'frontend/**'
    - name: Trigger Build-Portal FRONTEND
      # run only if some file in 'frontend' folder was changed
      if: steps.changes.outputs.frontend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
     - name: Trigger Build-Portal BACKEND
      # run only if some file not 'backend' folder was changed
      if: steps.changes.outputs.backend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
like image 87
GuiFalourd Avatar answered Feb 25 '26 06:02

GuiFalourd


I don't see the reason behind this complexity. Just use 2 YML files

frontend.yml => this is where you put path condition to match frontend path

on:
 push:
  branches: [ develop ]
  paths: 
   - 'frontend/**'

backend.yml => this is where you put path condition to match backend path

on:
 push:
  branches: [ develop ]
  paths: 
   - 'backend/**'

Both files will be evaluated everytime a push is done and GH will decide which flow to run.

You can always use a default yml file to run anyway whenever any change occurs outside these paths

like image 35
ProllyGeek Avatar answered Feb 25 '26 06:02

ProllyGeek