jenkins循环取参数执行构建命令
作者:互联网
接上一篇,curl命令可以远程执行job了,但是我们每次执行的job数量特别多,肯定要把job名做成参数然后循环取值,不停的执行
实现:
#!/usr/bin/env groovy
properties(
[parameters(
[string(defaultValue: "", description: "微服务名", name: "jobName")]
)]
)
node("master") {
stage("test") {
jobID = "${jobName}"
withCredentials([string(credentialsId: 'jenkinsIP', variable:'jenkinsIP')]) {
for (item in jobID.tokenize(',')){
echo "for里面的jobID = " + item
sh '''curl -o index2.html -u qm:.. -X post http://'''+jenkinsIP+'''/job/'''+item+'''/buildWithParameters?token=doJob'''
}
}
}
}
PS:jenkinsIP是凭据里配置的参数,item是循环获取服务名的参数,dojob是上一篇配置的token
使用效果:
标签:jenkinsIP,构建,jobID,item,job,参数,jenkins,curl 来源: https://blog.csdn.net/taoying220/article/details/120156810