通过 Web API 设置 Hudson 构建描述

发布于 2024-10-15 13:24:18 字数 113 浏览 6 评论 0原文

我有一个在 Hudson 构建上运行的 Python 脚本,并且希望能够以编程方式设置构建的描述。

我可以在构建页面上单击“添加描述”并填写表单,如何将一些数据 POST 到与表单相同的 URL?

I have a Python script that operates on Hudson builds and would love to be able to set the description of a build programmatically.

I can click "Add Description" on a build's page and fill in the form, how can I POST some data to the same URL that form does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

丢了幸福的猪 2024-10-22 13:24:18

弄清楚了,需要将以下内容作为表单数据(内容类型 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)

Figured it out, need to POST the following as form data (content type application/x-www-form-urlencoded) to

http://myserver/hudson/job/thebuild/10/submitDescription

{"description": "Some Description for the build"}

In code:

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)
夏有森光若流苏 2024-10-22 13:24:18

(会发表评论,但没有足够的代表)

感谢 jtb 提供的大部分方法。如果服务器上启用了安全性,我发现我可以使用此代码进行身份验证(改编自 此处

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:///me/configure

(would comment, but not enough rep)

Thanks to jtb for the bulk of the approach. If security is enabled on the server, I found that I could authenticate using this code (adapted from 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)

The values for user and token can be found under API Token in: http://<myserver>/me/configure

无远思近则忧 2024-10-22 13:24:18

使用“执行系统 ​​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")
    }

Using an 'Execute system Groovy script' Build task:

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")
    }
染火枫林 2024-10-22 13:24:18

这是在 shell 中运行良好的curl 命令。替换之间的文本(包括 {})。

curl -X POST -u {用户:密码} -H '内容类型:application/x-www-form-urlencoded' --data-urlencode 描述={描述字符串} {hudsonurl}/job/{jobname}/{buildnumber }/提交描述

Here is the curl command that worked fine from shell. Replace the text in between and including {}.

curl -X POST -u {user:password} -H 'Content-Type: application/x-www-form-urlencoded' --data-urlencode description={descriptionstring} {hudsonurl}/job/{jobname}/{buildnumber}/submitDescription

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文