-
Notifications
You must be signed in to change notification settings - Fork 4
40 lines (35 loc) · 1.02 KB
/
trigger.jenkins.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: Trigger Jenkins Job
on:
push:
branches:
- main
- dev
pull_request:
types: [closed]
branches:
- main
- dev
jobs:
trigger-jenkins:
runs-on: ubuntu-latest
steps:
- name: Set Jenkins job name based on branch
id: jenkins_job_name
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "job_name=frontend" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
echo "job_name=frontend_dev" >> $GITHUB_ENV
else
echo "No Jenkins job to trigger for this branch."
exit 0
fi
- name: Trigger Jenkins job
if: env.job_name != ''
env:
JENKINS_URL: ${{vars.JENKINS_URL}}
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
JOB_NAME: ${{ env.job_name }}
run: |
echo "Triggering Jenkins job $JOB_NAME"
curl -X POST "$JENKINS_URL/buildByToken/build?job=$JOB_NAME&token=$JENKINS_TOKEN"