如何说服詹金斯分享几个作业集结号? [英] How to convince jenkins to share a build number for several jobs?

查看:148
本文介绍了如何说服詹金斯分享几个作业集结号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从开发团队设置的要求构建系统,使每个版本将对所有分支机构的唯一版本号。

I do have a requirement from the development team to setup the build system so each build will have an unique build number for all branches.

该版本使用的作业,每个分支詹金斯制成。

The builds are made by jenkins using jobs for each branch.

有一个詹金斯插件,可以设置为工作在未来buildnumber但是这是至少有两个原因有点没用的:

There is a jenkins plugin that can setup the next buildnumber for a job but this is kinda useless for at least two reasons:


  • 将设置一个作业内部版本号,你可以不知道一切是如何设置它为所有的分支,因为它们可以被删除或随时补充

  • 它不设置它当前构建

如何我们得到的内部版本号:我们做与分支名称和混帐/善变的修订号的HTTP调用。在此基础上集中SEVER是给了我们一个版本号作为响应。如果你用相同的参数调用它两次,你会得到相同的响应(预期的行为)。

How to we get the build numbers: we do make a HTTP call with the branch name and the revision number in git/mercurial. Based on this the centralized sever is giving us a build number as a response. If you call it twice with the same parameters, you will get the same response (desired behaviour).

现在,我们如何调整詹金斯使用相同的版本号为我们吗?很显然,我可以使用从脚本返回的版本号,但就业人数会有所不同,我怀疑詹金斯就知道我感动我的剧本里的BUILD_NUMBER变量。

Now, how can we tweak jenkins to use the same build numbers as us? Obviously I could use the build number returned from the script, but the job number would be different and I doubt jenkins will know that I touched the BUILD_NUMBER variable inside my script.

主要是,我需要的是某种pre-工作启动脚本,我可以运行,一前的版本号分配给作业将运行。

Mainly, what I need is some kind of pre-job-start script that I can run, one that would run before the build number is assigned to the job.

推荐答案

您可以使用环境喷油器插件与运行前评估Groovy脚本。我几乎同样的要求,但对我来说,只能用相同 job_ preFIX _ 的工作在他们的名字相同的唯一 nextBuildNumber (换句话说,其他作业与 job_ prefix2 _ 在他们的名字的份额不同的 nextBuildNumber )。

You can use the Environment Injector Plugin to evaluate a Groovy script before your run. I have almost the same requirement, however for me, only the jobs with the same job_prefix_ in their name share the same unique nextBuildNumber (in other words, other jobs with job_prefix2_ in their name share a different nextBuildNumber).

评估的Groovy脚本部分,请使用:

import jenkins.model.*

// Access to the Jenkins instance
jenkins_instance = jenkins.model.Jenkins.instance

// Select jobs that match.
job_name = "^job_prefix_.*"
allItems = jenkins_instance.items
chosenJobs = allItems.findAll{ job -> job.name.matches(job_name) }

// Get the max
build_number = chosenJobs.collect{ it -> it.nextBuildNumber }.max()

// Increase next build number
currentJob.nextBuildNumber = build_number + 1

// and use it.
def map = [BUILD_NUMBER: build_number]
return map

这篇关于如何说服詹金斯分享几个作业集结号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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