如何在通过curl触发构建时设置Jenkins构建描述? [英] How can I set Jenkins build description while triggering build via curl?
问题描述
我试图设置我触发的构建的构建描述,因为我开始构建,我没有运气到目前为止。
我遇到了一个解决方案(添加文本到由Jenkins远程API触发的构建的页面),我有一种工作方式(第一个命令将启动构建,第二个将设置描述最后一个版本):
curl -v -X POSThttp:// [myServer] / job / [jobName] / build
curl -v -X POSThttp:// [myServer] / job / [jobName / lastBuild / submitDescription--data-urlencodedescription = test description
$ c $然而,问题是,如果我刚刚启动的构建排队/不立即踢,lastBuild将不参考
所以我试过这样:
payload ='json = {description}
curl -v -X POST -H类型:application / json-d $ payloadhttp:// [myServer] / job / [jobName] / build
b $ b
但实际上并没有设置描述。
任何想法如何实现?
我发现的其他解决方案,但我不太满意:
- 更改Jenkins构建名称&通过API在JAVA中描述 - 这也是一个后触发解决方案,将无法可靠地工作,只是设置描述后
- 修改Jenkins的构建说明 - 我想我可以构建一个检查,只有修改描述,当它是空的所以我不重写它,但这似乎相当复杂。
解决方案您可以总是有一个变量,并将构建描述传递到初始调用的变量中。然后在构建结束时,将该变量输出到控制台,并使用 描述设置插件 。
编辑以澄清:
- 安装 说明Setter插件
- 在作业配置中,配置一个String参数,调用 MyDescription 。在构建步骤某处,执行Shell 或执行Windows批处理命令键入
echo Desc:$ MyDescription
- 在后期构建步骤中,选择>设置构建描述。
- 将正则表达式设为
^ Desc:(。*)
- 将描述设为
\1
- 从命令行触发器:
curl -v -X POST --data- urlencodeMyDescription = This is my deschttp:// [myServer] / job / [jobName] / buildWithParameters
(上面是一行)
I'm trying to set the build description of a build I'm triggering, as I'm kicking off the build, and I have no luck so far.
I came across a solution (Adding text to the page of a build triggered by the Jenkins remote API), and I kind of got it to work this way (first command will kick off the build, second one will set the description of the last build):
curl -v -X POST "http://[myServer]/job/[jobName]/build"
curl -v -X POST "http://[myServer]/job/[jobName/lastBuild/submitDescription" --data-urlencode "description=test description"
However, the problem is that if the build I just kicked off gets queued / doesn't kick of right away, "lastBuild" will not reference the build I just kicked off, but the one before it (that is still building).
So I tried something like this:
payload='json={""description"":""test description""}'
curl -v -X POST -H "Content-Type: application/json" -d $payload "http://[myServer]/job/[jobName]/build"
But it doesn't actually set the description.
Any ideas how this can be achieved?
Other solutions I found, but I'm not really happy with:
- Changing Jenkins Build Name & Description through API in JAVA - that's also a "post trigger solution" that won't work reliably same as just setting the description after
- Modifying Jenkins Description for a build - I guess I could build in a check, and only modify the description when it's empty so I don't override it, but that seems rather complicated. I'm thinking there must be an easier solution to this, no?
解决方案 You can always have a variable and pass the build description into the variable on the initial invocation. Then at the end of your build, output the variable to console and catch with Description Setter plugin.
Edit to clarify:
- Install Description Setter plugin.
- In the Job Configuration, configure a String parameter, call it "MyDescription", leave defaults blank.
- Somewhere in the build steps, either "Execute Shell" or "Execute Windows Batch Command" type
echo Desc: $MyDescription
or echo Desc: %MyDescription%
, depending on your OS.
- In the Post-Build steps, select "Set Build Description".
- Set Regular expression as
^Desc: (.*)
- Set Description as
\1
- From command line trigger by:
curl -v -X POST --data-urlencode "MyDescription=This is my desc" "http://[myServer]/job/[jobName]/buildWithParameters"
(that above is one line)
这篇关于如何在通过curl触发构建时设置Jenkins构建描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!