From 53adca8eb3b25b2640853866478be021b5578973 Mon Sep 17 00:00:00 2001 From: shehab khaled <89648315+shehab299@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:18:57 +0200 Subject: [PATCH] (CI) Added a github action to trigger jenkins pipelines (#43) --- .github/workflows/trigger.jenkins.yaml | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/trigger.jenkins.yaml diff --git a/.github/workflows/trigger.jenkins.yaml b/.github/workflows/trigger.jenkins.yaml new file mode 100644 index 00000000..cc1baa2b --- /dev/null +++ b/.github/workflows/trigger.jenkins.yaml @@ -0,0 +1,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" +