From 4e868453c22847cb6485274becdeb792aa409b3b Mon Sep 17 00:00:00 2001 From: Caralee Jackson Date: Mon, 30 Sep 2024 09:00:21 -0500 Subject: [PATCH] SYS-484 use action for jenkins trigger --- .github/workflows/qa-pipeline-trigger.yml | 133 ---------------------- .github/workflows/trigger-jenkins.yml | 23 ++++ 2 files changed, 23 insertions(+), 133 deletions(-) delete mode 100644 .github/workflows/qa-pipeline-trigger.yml create mode 100644 .github/workflows/trigger-jenkins.yml diff --git a/.github/workflows/qa-pipeline-trigger.yml b/.github/workflows/qa-pipeline-trigger.yml deleted file mode 100644 index d86409c..0000000 --- a/.github/workflows/qa-pipeline-trigger.yml +++ /dev/null @@ -1,133 +0,0 @@ -#name: Shardeum Reusable Workflow to trigger an external QA Pipeline -### TODO - This is a copy of the WIP steps to trigger a Jenkins QA job. We pulled this code from the primary -### CI workflow to simplify it and to work on correcting some issues in the QA Job trigger. This workflow -### currently DOES NOT WORK. It can only be manually triggered and that will end in sadness. I'm committing -### this as is because we'll be working on it again in the future and I don't want to lose it in a stale -### branch. I'm going to copy everything out to ensure Github doesn't try to run it and cause a weird error. -### See Linear issues SYS-136 and other Systems and Automation Team linear issues for more info. -### TODO - We should probably make this stuff a little more generic just in case we ever decide to use something other than Jenkins -### I started doing that but haven't finished. There are a few org/repo vars that'll need to be removed and recreated -### All variables must be set at the repo workflow call and provided to this shared/reusable workflow -#on: -# workflow_call: -# inputs: -# base-url: -# required: true -# type: string -# qa-job: -# required: true -# type: string -# qa-job-required: -# required: true -# type: boolean -### TODO - not sure if we'll need these permissions or not -#permissions: -# issues: write -# pull-requests: write -# -#env: -# JENKINS_URL: ${{ inputs.jenkins-url }} -# JENKINS_QA_JOB: ${{ inputs.jenkins-qa-job }} -# IS_JENKINS_QA_REQUIRED: ${{ inputs.jenkins-qa-required }} -# -#jobs: -# debug-info: -# runs-on: ubuntu-latest -# name: Display useful debugging information -# steps: -# - name: Display Event details -# run: | -# echo "Event Name: ${{ github.event_name }}" -# echo "Event Action: ${{ github.event.action }}" -# echo "Event Sender Type: ${{ github.event.sender.type }}" -# -# - name: Echo Input Values and Check Defaults -# run: | -# echo "*** Start - Check inputs in shared workflow ***" -# echo "Jenkins URL - Var: ${{ vars.JENKINS_URL }} | Input: ${{ inputs.jenkins-url }} | Env: ${{ env.JENKINS_URL }}" -# echo "Jenkins QA Job - Var: ${{ vars.JENKINS_QA_JOB }} | Input: ${{ inputs.jenkins-qa-job }} | Env: ${{ env.JENKINS_QA_JOB }}" -# echo "Jenkins QA Required - Var: ${{ vars.IS_JENKINS_QA_REQUIRED }} | Input: ${{ inputs.jenkins-qa-required }} | Env: ${{ env.IS_JENKINS_QA_REQUIRED }}" -# echo "*** End - Check inputs in shared workflow ***" -# -### This job is needed to get around the fact that GitHub doesn't let you reference an env in the 'if' for the job -# is-qa-available: -# name: Determine Jenkins Job Requirement -# runs-on: ubuntu-latest -# outputs: -# run-jenkins: ${{ steps.check.outputs.run-jenkins }} -# steps: -# - name: Check if Jenkins QA job is required -# id: check -# run: | -# if [ -n "${{ env.JENKINS_QA_JOB }}" ]; then -# echo "run-jenkins=true" >> $GITHUB_ENV -# echo "run-jenkins=true" >> $GITHUB_OUTPUT -# else -# echo "run-jenkins=false" >> $GITHUB_ENV -# echo "run-jenkins=false" >> $GITHUB_OUTPUT -# fi -# - name: Log run-jenkins output -# run: | -# echo "run-jenkins: ${{ steps.check.outputs.run-jenkins }}" -# trigger-qa-job: -# name: Trigger QA Job -# needs: [merge-checks, determine-jenkins] -# runs-on: ubuntu-latest -# if: ${{ github.event_name != 'issue_comment' && needs.determine-jenkins.outputs.run-jenkins == 'true' }} -# steps: -# - name: Echo Input Values and Check Defaults -# run: | -# echo "Jenkins job Required: ${{ env.IS_JENKINS_QA_REQUIRED }}" -# echo "Jenkins job Required: ${{ env.JENKINS_QA_JOB }}" -# - name: Configure -# id: configure -# run: | -### Determine the branch name -# if [ "${{ github.event_name }}" == "pull_request" ]; then -# BRANCH_NAME=${{ github.head_ref }} -# else -# BRANCH_NAME=${{ github.ref_name }} -# fi -# echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV -# -### Determine the repository name, prioritize the secret if it exists -# if [ -n "${{ env.REPO_NAME }}" ]; then -# REPO_NAME=${{ env.REPO_NAME }} -# else -# REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2) -# fi -# -### Capitalize the repository name -# REPO_NAME_CAPITALIZED=$(echo "${REPO_NAME:0:1}" | tr '[:lower:]' '[:upper:]')${REPO_NAME:1} -# -### Export the environment variables -# echo "REPO_NAME=${REPO_NAME_CAPITALIZED}" >> $GITHUB_ENV -# -# - name: Trigger QA Job -# id: trigger_qa_job -# env: -# BRANCH_NAME: ${{ env.BRANCH_NAME }} -# REPO_NAME: ${{ env.REPO_NAME }} -# JENKINS_URL: ${{ env.JENKINS_URL }} -# run: | -# curl -f -X POST "${JENKINS_URL}/job/${{ env.JENKINS_QA_JOB }}/buildWithParameters?SPECIFY_${REPO_NAME}_BRANCH=true&${REPO_NAME}_BRANCH=${BRANCH_NAME}" \ -# --user "${{ secrets.JENKINS_API_CREDS }}" -# continue-on-error: true -# -# - name: Check if any step failed -# id: check_failure -# run: | -# failed=false -# -#### Check Jenkins QA job - This just checks that the workflow step passes but will later be configured to wait for the actual Jenkins job to pass/fail -# if [[ "${{ steps.trigger_jenkins_qa_job.outcome }}" == "failure" ]]; then -# echo "ERROR! Step 'Trigger Jenkins QA Job' has failed!" -# if ${{ env.IS_JENKINS_QA_REQUIRED }}; then -# failed=true -# fi -# fi -# if [ "$failed" == "true" ]; then -# echo "Please expand the failed step(s) for more details." -# exit 1 -# fi -# \ No newline at end of file diff --git a/.github/workflows/trigger-jenkins.yml b/.github/workflows/trigger-jenkins.yml new file mode 100644 index 0000000..d058155 --- /dev/null +++ b/.github/workflows/trigger-jenkins.yml @@ -0,0 +1,23 @@ +name: Trigger Jenkins Job on Dev Merge +# I'm initially using this action because it's easy to configure but it uses polling from GitHub rather +# than waiting on Jenkins to notify it that the job has completed so we might consider refactoring this +# in the future as polling is more taxing on both applications and can lead to a delay in notification + +on: + push: + branches: + - dev + +jobs: + trigger-jenkins: + runs-on: ubuntu-latest + steps: + - name: Trigger Jenkins Job + uses: mickeygoussetorg/trigger-jenkins-job@main + with: + jenkins-server: ${{ vars.JENKINS_URL }} # Jenkins URL + jenkins-job: ${{ vars.JENKINS_JOB }} # Defaulted on org, can override on repo + jenkins-username: ${{ secrets.JENKINS_USER }} + jenkins-pat: ${{ secrets.JENKINS_TOKEN }} + poll-time: ${{ vars.JENKINS_POLL_TIME }} # # Defaulted on org, can override on repo + timeout-value: ${{ vars.JENKINS_TIMEOUT }} # Defaulted on org, can override on repo \ No newline at end of file