如何在Jenkins文件中(以Groovy脚本的形式)表示Jenkins作业配置的Notifications Endpoint部分?我已经安装了Notification插件,但不确定如何使用。
答案 0 :(得分:0)
在詹金斯管道中,我执行了以下操作:
pipeline {
// ..
stages {
stage('Notify') {
script {
def build = currentBuild // global variable in pipeline -> https://opensource.triology.de/jenkins/pipeline-syntax/globals#currentBuild
def targetUrl = "http://some-url?{some-query-params}"
def buildUrl = build.absoluteUrl
def buildNumber = build.number
def buildStatus = build.currentResult
httpRequest url: targetUrl, contentType: 'APPLICATION_JSON', httpMode: 'POST', responseHandle: 'NONE', timeout: 30, requestBody: """
{
"name": "${args.serviceName}",
"build": {
"full_url": "${buildUrl}",
"number": "${buildNumber}",
"phase": "FINISHED",
"status": "${buildStatus}"
}
}
"""
}
}