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

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

问题描述

我正在尝试将jenkins流水线作为代码.我正在使用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天全站免登陆