diff --git a/pipeline.groovy b/pipeline.groovy index 7a437e9..0eb2d52 100644 --- a/pipeline.groovy +++ b/pipeline.groovy @@ -8,11 +8,14 @@ pipeline { UNIT_TEST_STAGE_STATUS = "FAIL" PYPI_STAGE_STATUS = "FAIL" AUTO_DOC_STAGE_STATUS = "FAIL" + // WEBHOOK PAYLOAD AND COMMIT DETAILS WEBHOOK_SENDER_EMAIL = "" WEBHOOK_SENDER_NAME = "" WEBHOOK_SENDER_LOGIN = "" COMMIT_HASH = "" COMPARE_URL = "" + COMMIT_MSG = "" + BRAND_REF = "" } stages { @@ -32,18 +35,22 @@ pipeline { stage('Webhook Handler') { steps { script { - // Get the raw JSON content from the REQUEST_CONTENT environment variable - // def rawPayload = env.REQUEST_CONTENT - + echo '------- START RAW WEBHOOK PAYLOAD -------' + echo payload + echo '------- END RAW WEBHOOK PAYLOAD -------' + } + script { // Parse the JSON content using jsonSlurper def jsonSlurper = new groovy.json.JsonSlurper() def jsonPayload = jsonSlurper.parseText(payload) - WEBHOOK_SENDER_EMAIL=jsonPayload.sender.email - WEBHOOK_SENDER_NAME=jsonPayload.sender.full_name - WEBHOOK_SENDER_LOGIN=jsonPayload.sender.login - COMMIT_HASH=jsonPayload.after - COMPARE_URL=jsonPayload.compare_url + WEBHOOK_SENDER_EMAIL=jsonPayload.sender.email || currentBuild.getBuildCauses()[0].userId + WEBHOOK_SENDER_NAME=jsonPayload.sender.full_name || "Manually " + currentBuild.getBuildCauses()[0].shortDescription + WEBHOOK_SENDER_LOGIN=jsonPayload.sender.login || "N/A: Manual trigger" + COMMIT_HASH=jsonPayload.after || sh (script: "cd webhook-test && git log -n 1 --pretty=format:'%H'", returnStdout: true) + COMPARE_URL=jsonPayload.compare_url || "N/A: Manual trigger" + COMMIT_MSG=jsonPayload.head_commit.message || sh (script: "cd webhook-test && git log -n 1 --pretty=format:'%B'", returnStdout: true) + BRANCH_REF=jsonPayload.ref || "N/A: Manual trigger" } } } @@ -71,11 +78,16 @@ pipeline { body: """ Results of Hub/release Pipeline ${env.BUILD_TAG} -Build triggered by: "${WEBHOOK_SENDER_NAME} - ${WEBHOOK_SENDER_LOGIN}" -Commit hash: "${COMMIT_HASH}" -See changes: "${COMPARE_URL}" -Email: "${WEBHOOK_SENDER_EMAIL}" +Build triggered by: ${WEBHOOK_SENDER_NAME} - ${WEBHOOK_SENDER_LOGIN} +Email: ${WEBHOOK_SENDER_EMAIL} +--- Commit details --- +HEAD Commit: ${COMMIT_HASH} +Commit message: ${COMMIT_MSG} +Branch: ${BRANCH_REF} +See changes: ${COMPARE_URL} + +--- Pipeline stage status --- Clone Stage: ${CLONE_STAGE_STATUS} Generate Build Information Stage: ${GENERATE_BUILD_INFORMATION_STAGE_STATUS} Build Stage : ${BUILD_STAGE_STATUS}