From 60d4f171c67880ba83f79338ffc37205e069d7d1 Mon Sep 17 00:00:00 2001 From: Cristian Gamboa Date: Wed, 27 Nov 2024 08:16:42 -0500 Subject: [PATCH] :recycle: refactor(project): Add action to trigger pipeline on code changes --- .github/workflows/jenkins-trigger.yml | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/jenkins-trigger.yml diff --git a/.github/workflows/jenkins-trigger.yml b/.github/workflows/jenkins-trigger.yml new file mode 100644 index 000000000..d4c56fde5 --- /dev/null +++ b/.github/workflows/jenkins-trigger.yml @@ -0,0 +1,29 @@ +name: Trigger Jenkins Job + +on: + push: + branches: + - '**' # This will trigger the workflow on any branch that receives a push + workflow_dispatch: # This allows the workflow to be manually triggered if needed + +jobs: + trigger-job: + runs-on: ubuntu-latest + + steps: + # Step 1: Get the branch name and build the URL for Jenkins + - name: Get branch name and build Jenkins URL + run: | + BRANCH_NAME=${GITHUB_REF#refs/heads/} # Remove 'refs/heads/' from GITHUB_REF + JENKINS_URL="https://automation.prms.cgiar.org/job/prms-reporting-tool-${BRANCH_NAME}/build" + echo "Jenkins job URL for the branch $BRANCH_NAME is: $JENKINS_URL" + echo "JENKINS_URL=${JENKINS_URL}" >> $GITHUB_ENV + + # Step 2: Execute the curl command to trigger the job in Jenkins with the dynamically built URL + - name: Trigger Jenkins Job + run: | + curl -X POST ${{ env.JENKINS_URL }} --user ${{ secrets.JENKINS_USERNAME }}:${{ secrets.JENKINS_API_TOKEN }} + env: + JENKINS_URL: ${{ env.JENKINS_URL }} + JENKINS_USERNAME: ${{ secrets.JENKINS_USERNAME }} + JENKINS_API_TOKEN: ${{ secrets.JENKINS_API_TOKEN }} \ No newline at end of file