我有一个在Hudson版本上运行的Python脚本,并且希望能够以编程方式设置构建的描述。
我可以在构建页面上单击“添加描述”并填写表单,如何将某些数据发布到与表单相同的URL?
答案 0 :(得分:7)
想出来,需要将以下内容作为表单数据(内容类型application/x-www-form-urlencoded
)发送到
http://myserver/hudson/job/thebuild/10/submitDescription
{"description": "Some Description for the build"}
在代码中:
def set_description(build_url, desc):
req_data = urllib.urlencode({'description': desc})
req = urllib2.Request(build_url + '/submitDescription', req_data)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
urllib2.urlopen(req)
答案 1 :(得分:2)
使用'执行系统Groovy脚本'构建任务:
import hudson.model.Cause
import hudson.model.Job
import jenkins.model.Jenkins
final JOB_NAME = 'my-job-name'
final jenkins = Jenkins.instance
final job = jenkins.getItemByFullName(JOB_NAME, Job.class)
final currentBuild = Thread.currentThread().executable
final buildNumber = currentBuild.getNumber()
job.builds
.findAll { build ->
build.number == buildNumber
}
.each { build ->
build.setDescription("Some Description for the build")
}
答案 2 :(得分:2)
(会评论,但代表不够)
感谢jtb的大部分方法。如果在服务器上启用了安全性,我发现我可以使用此代码进行身份验证(改编自here)
def set_description(build_url, desc, user, token):
import base64, urllib, urllib2
req_data = urllib.urlencode( {'description': desc } )
req = urllib2.Request(build_url + '/submitDescription', req_data)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
auth = 'Basic {}'.format(base64.b64encode("{}:{}".format( user, token )))
req.add_header( 'Authorization', auth )
response = urllib2.urlopen(req)
用户和令牌的值可在API令牌下找到:http://<myserver>/me/configure
答案 3 :(得分:0)
这是从shell运行良好的curl命令。替换之间的文本,包括{}。
curl -X POST -u {user:password} -H'Content-Type:application / x-www-form-urlencoded'--data-urlencode description = {descriptionstring}} {hudsonurl} / job / {jobname} / {buildnumber} / submitDescription