Generic Webhook Trigger 远程触发
jenkins安装Generic Webhook Trigger插件然后配置如下
·
jenkins安装Generic Webhook Trigger插件
然后配置如下
最后送上pipeline完整脚本
pipeline {
agent any
options{ timestamps () }
triggers {
GenericTrigger(
genericVariables: [
[key: 'ref', value: '$.ref']
],
token: 'jsj',
//causeString: ' Triggered on $ref',
//regexpFilterText: '$ref',
printContributedVariables: true,
printPostContent: true
)
}
stages {
stage('syntax-check') {
steps {
ansiblePlaybook (
//inventory: '${hos}',
colorized: true,
playbook: '${book}',
limit: '10.22.8.33,10.22.32.2',
extras: '--syntax-check'
)
}
}
stage('Deloy') {
steps {
ansiblePlaybook (
//inventory: '${hos}',
playbook: '${book}',
limit: '10.22.1.33,10.22.1.2',
)
}
}
stage('GWT') {
steps {
sh '''
echo $ref
printenv
'''
}
}
}
}
远程触发方式
请求参数: curl -vs http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=jsj 2>&1
令牌头: curl -vs -H "token: jsj" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1
类型Bearer的授权标头:curl -vs -H "Authorization: Bearer jsj" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1
PS:
添加参数"Content-Type:application/json会得到触发日志
curl -X POST -H "Content-Type:application/json" -d '{"ref":refs/heads/master" }' -vs http://10.22.1.34:8080/generic-webhook-trigger/invoke?token=jsj
如下
GenericWebhookEnvironmentContributor
Received:
{"ref":refs/heads/master" }
Contributing variables:
ref = refs/heads/master"
更多推荐
已为社区贡献3条内容
所有评论(0)