-
Notifications
You must be signed in to change notification settings - Fork 7
70 lines (62 loc) · 2.62 KB
/
trigger-jenkins.yml
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Trigger Jenkins Build
on:
push:
branches:
- '*' # Trigger on all branches
pull_request:
branches:
- '*' # Trigger on all branches
jobs:
trigger-jenkins:
runs-on: ubuntu-22.04
steps:
- name: Print secrets for debugging purposes
run: |
echo "Printing secrets for debugging purposes..."
echo "JENKINS_URL: ${{ secrets.JENKINS_URL }}"
echo "JOB_NAME: ${{ secrets.JOB_NAME }}"
echo "JENKINS_USER: ${{ secrets.JENKINS_USER }}"
echo "JENKINS_API_TOKEN: ${{ secrets.JENKINS_API_TOKEN }}"
- name: Set up environment variables
run: |
echo "Setting up environment variables..."
export JENKINS_URL="${{ secrets.JENKINS_URL }}"
export JOB_NAME="${{ secrets.JOB_NAME }}"
export JENKINS_USER="${{ secrets.JENKINS_USER }}"
export JENKINS_API_TOKEN="${{ secrets.JENKINS_API_TOKEN }}"
echo "JENKINS_URL is set to $JENKINS_URL"
echo "JOB_NAME is set to $JOB_NAME"
echo "JENKINS_USER is set to $JENKINS_USER"
echo "GIT_COMMIT: ${{ github.sha }}"
echo "GIT_BRANCH: ${{ github.ref }}"
echo "PR_NUMBER: ${{ github.event.number }}"
echo "GITHUB_REPO: ${{ github.repository }}"
- name: Test DNS Resolution
run: |
echo "Testing DNS resolution for Jenkins URL..."
JENKINS_HOST=$(echo "${{ secrets.JENKINS_URL }}" | sed -E 's|^[^/]+://([^/:]+).*|\1|')
echo "Extracted Jenkins Host: $JENKINS_HOST"
nslookup $JENKINS_HOST || exit 1
- name: Test Jenkins URL
run: |
echo "Testing Jenkins URL..."
curl -I "${{ secrets.JENKINS_URL }}" || exit 1
- name: Trigger Jenkins Build
if: success() # Proceed only if the previous steps succeed
env:
JENKINS_URL: ${{ secrets.JENKINS_URL }}
JOB_NAME: ${{ secrets.JOB_NAME }}
JENKINS_USER: ${{ secrets.JENKINS_USER }}
JENKINS_API_TOKEN: ${{ secrets.JENKINS_API_TOKEN }}
GIT_COMMIT: ${{ github.sha }}
GIT_BRANCH: ${{ github.ref }}
PR_NUMBER: ${{ github.event.number }}
GITHUB_REPO: ${{ github.repository }}
run: |
echo "Triggering Jenkins build..."
curl -X POST "$JENKINS_URL/job/$JOB_NAME/buildWithParameters?token=$JENKINS_API_TOKEN" \
--user "$JENKINS_USER:$JENKINS_API_TOKEN" \
--data-urlencode "GIT_COMMIT=$GIT_COMMIT" \
--data-urlencode "GIT_BRANCH=$GIT_BRANCH" \
--data-urlencode "PR_NUMBER=$PR_NUMBER" \
--data-urlencode "GITHUB_REPO=$GITHUB_REPO"