added a file #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |