Add payload guard
This commit is contained in:
parent
f11631e9d0
commit
dbe5ebc7c6
|
@ -42,15 +42,26 @@ pipeline {
|
|||
script {
|
||||
// Parse the JSON content using jsonSlurper
|
||||
def jsonSlurper = new groovy.json.JsonSlurper()
|
||||
def jsonPayload = jsonSlurper.parseText(payload)
|
||||
def jsonPayload = payload ? jsonSlurper.parseText(payload) : null
|
||||
|
||||
payload ? {
|
||||
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"
|
||||
} : {
|
||||
WEBHOOK_SENDER_EMAIL=currentBuild.getBuildCauses()[0].userId
|
||||
WEBHOOK_SENDER_NAME="Manually " + currentBuild.getBuildCauses()[0].shortDescription
|
||||
WEBHOOK_SENDER_LOGIN="N/A: Manual trigger"
|
||||
COMMIT_HASH=sh (script: "cd webhook-test && git log -n 1 --pretty=format:'%H'", returnStdout: true)
|
||||
COMPARE_URL="N/A: Manual trigger"
|
||||
COMMIT_MSG=sh (script: "cd webhook-test && git log -n 1 --pretty=format:'%B'", returnStdout: true)
|
||||
BRANCH_REF="N/A: Manual trigger"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user