简体   繁体   English

Jenkins作业可以在开始构建时设置描述构建吗

[英]Can a Jenkins job set the description build upon starting the build

I am familiar with the Description Setter plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Description+Setter+Plugin ), but it only kicks in as a post-build action . 我对Description Setter插件https://wiki.jenkins-ci.org/display/JENKINS/Description+Setter+Plugin )熟悉,但是它只是作为构建后的动作加入 I have some very long testing builds and I would like to set the build description right on the start - either as a pre-build or as a build step. 我有一些很长的测试版本,我想一开始就设置版本描述-作为预构建或构建步骤。

Use pre-scm-build step and Conditional Build Step plugins. 使用pre-scm-build步骤Conditional Build Step插件。 In global configuration, find "Conditional Build step" section, and select "any builder" (or something similar). 在全局配置中,找到“有条件的构建步骤”部分,然后选择“任何构建器”(或类似的东西)。 This will allow the plugin to use any build or post-build step. 这将允许插件使用任何构建或构建后步骤。

Then in the job configuration, under Build Environment, use "Run buildstep before SCM runs", and select Conditional Build Step. 然后,在作业配置中的“构建环境”下,使用“在SCM运行之前运行构建步骤”,然后选择“条件构建步骤”。 Leave the condition to "always", and select "Description Setter". 将条件保留为“始终”,然后选择“描述设置器”。

FWIW, in my environment with latest plugins, I can execute "Description Setter" from pre-SCM step without the need for Conditional Build step. FWIW,在具有最新插件的环境中,我可以从SCM之前的步骤执行“描述设置器”,而无需执行条件构建步骤。

Since my build is submitted from a Python script, I added a kludge in the script: 由于我的构建是通过Python脚本提交的,因此我在脚本中添加了一个kludge:
1. Wait until it starts executing and find its build ID in the job (I can uniquely identify my build by the build parameters that were used) 1.等待它开始执行,然后在作业中找到其构建ID(我可以通过使用的构建参数来唯一标识我的构建)
2. Having the job name and the build number, use the Jenkins CLI (jar file) to set the description. 2.具有作业名称和内部版本号,使用Jenkins CLI(jar文件)设置描述。

Admittedly, the solution proposed by Slav is more elegant, but I have not gotten around to test it...Once I do, I will report here. 诚然,Slav提出的解决方案更加优雅,但是我还没有进行测试……一旦完成,我将在这里报告。

You can also add a groovy build step (which should be the first step), that will use the build parameters, like this: 您还可以添加一个常规的构建步骤(应该是第一步),该步骤将使用构建参数,如下所示:

/* Get System name, version, user name */
def system  = build.getEnvironment(listener).get('system')
def version = build.getEnvironment(listener).get('system_version')
def user    = build.getEnvironment(listener).get('USERNAME')

/* Build description with params and send description to currentbuild */
def description = "$system / $version / $user"
currentBuild.setDescription(description)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM