如何在通过curl触发构建时设置Jenkins构建描述? [英] How can I set Jenkins build description while triggering build via curl?

查看:2174
本文介绍了如何在通过curl触发构建时设置Jenkins构建描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设置我触发的构建的构建描述,因为我开始构建,我没有运气到目前为止。



我遇到了一个解决方案(添加文本到由Jenkins远程API触发的构建的页面),我有一种工作方式(第一个命令将启动构建,第二个将设置描述最后一个版本):

  curl -v -X POSThttp:// [myServer] / job / [jobName] / build
curl -v -X POSThttp:// [myServer] / job / [jobName / lastBuild / submitDescription--data-urlencodedescription = test description


所以我试过这样:

  payload ='json = {description}
curl -v -X POST -H类型:application / json-d $ payloadhttp:// [myServer] / job / [jobName] / build


b $ b

但实际上并没有设置描述。



任何想法如何实现?



我发现的其他解决方案,但我不太满意:




解决方案

您可以总是有一个变量,并将构建描述传递到初始调用的变量中。然后在构建结束时,将该变量输出到控制台,并使用 描述设置插件



编辑以澄清




  • 安装 说明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:

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆