![](/img/trans.png)
[英]Unit test results not showing in Sonar when building child projects in Jenkins
[英]Bitbucket webhook and Jenkins, showing build results
是否可以將 Bitbucket webhook 與 Jenkins 一起使用並在 Bitbucket 上顯示構建結果?
有沒有人達到這個組合? 在 Bitbucket 上使用 webhook 時,如何顯示 Jenkins 的構建結果?
最后我使用 Bitbucket REST API 來顯示 Z2E54334C0A5CE2E3E3E5A5845DF3AB3 上的構建狀態,是最簡單和最靈活的方式:
https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/
我使用 Jenkins 通用 Webhook 觸發器從打開的 PR 中獲取有效負載,例如 commitId: https://plugins.jenkins.io/generic-webookh
def notifyBitBucket(commitId, state) {
withCredentials([string(credentialsId: ‘[your-bitbucket-user-token], variable: 'TOKEN')]) {
try {
sh """
curl --location --request POST “[your-bitbucket-repo]/rest/build-status/1.0/commits/${commitId}" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${TOKEN}" \
--data-raw '{
"state": "${state}",
"key": "pipeline-webhook",
"name": "pipeline-webhook",
"url": "${BUILD_URL}/console#footer",
"description": “[something describing your build]”
}'
"""
} catch(e) {
echo 'Notify failed, trying again... error: ' + ex.toString()
notifyBitBucket(commitId, state)
}
}
}
node {
try {
stage('Build') {
notifyBitBucket(commitId, "INPROGRESS");
... your logic
notifyBitBucket(commitId, "SUCCESSFUL");
} catch(ex) {
echo 'Build failed with error: ' + ex.toString()
notifyBitBucket(commitId, "FAILED");
currentBuild.result = 'FAILED'
}
}
我添加了 try catch,因為有時 API 會失敗。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.