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.
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"}'
...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With