无法获取詹金斯工作或参数的描述字段

时间:2019-03-20 14:29:01

标签: jenkins jenkins-plugins

是否可以在运行时或更高版本(如BUILD_ID或JOB_NAME)获得作业描述或作业参数描述?

我只搜索插件或解决方法。

谢谢。

1 个答案:

答案 0 :(得分:1)

这将是提示/解决方法

https://<<yourjenkinsdomain>>/job/<<yourjobname>>/configure (will open the configuration of your job)

但是

https://<<yourjenkinsdomain>>/job/<<yourjobname>>/config.xml (will give the job configuration in an xml format)

您可以在运行时通过curl或使用jenkins cli下载此xml,并使用带有-B选项的grep查找每个值的描述。

考虑到您已复制名称为“ config.xml”的

cat config.xml | grep -B 1 "description"

将为您提供描述和构建参数名称

 Grep command 
 -B NUM, --before-context=NUM
          Print  NUM  lines  of  leading  context  before  matching lines.
          Places  a  line  containing  a  group  separator  (--)   between
          contiguous  groups  of  matches.  With the -o or --only-matching
          option, this has no effect and a warning is given.

样本输出:

cat config.xml | grep -B 1 "description"

<actions/>
<description>Job description : Automation </description>
--
<name>branch</name>
<description>mandatory parameter , used for automation</description>

-

替代:

jenkins cli可以设置值

set-build-description   Sets the description of a build.
set-build-parameter Update/set the build parameter of the current build in progress. [deprecated]

您可以编写一个小脚本,然后将值转换为变量并使用它们