从 Jenkinsfile 设置管道名称和描述 [英] Set the pipeline name and description from Jenkinsfile

查看:20
本文介绍了从 Jenkinsfile 设置管道名称和描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 jenkins 管道作为代码进行 poc.我正在使用 Github 组织文件夹插件来扫描 Github 组织并为每个分支创建作业.有没有办法明确定义从 Jenkinsfile 获得的管道作业的名称?我还想为这些职位添加一些描述.

I am trying to do a poc of jenkins pipeline as code. I am using the Github organization folder plugin to scan Github orgs and create jobs per branch. Is there a way to explicitly define the names for the pipeline jobs that get from Jenkinsfile? I also want to add some descriptions for the jobs.

推荐答案

你需要像下面这样使用 currentBuild.node部分很重要

You need to use currentBuild like below. The node part is important

node {
    currentBuild.displayName = "$yournamevariable-$another"
    currentBuild.description = "$yourdescriptionvariable-$another"
}

上面的一个重命名构建,原始问题是关于重命名工作.管道中的以下脚本将执行此操作(这需要适当的权限)

Above one renames build where as Original question is about renaming jobs. Following script in pipeline will do that(this requires appropriate permissions)

item = Jenkins.instance.getItemByFullName("originalJobName")
item.setDescription("This description was changed by script")
item.save()
item.renameTo("newJobName")

这篇关于从 Jenkinsfile 设置管道名称和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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