Jenkins-将更新的修订传递给下游工作 [英] Jenkins - passing updated revision to downstream jobs

查看:136
本文介绍了Jenkins-将更新的修订传递给下游工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已将构建系统从CruiseControl移至jenkins,以用于多平台产品.这是一个单一的整体工作:
1.检查更改
2.更新属性文件中的产品内部版本号
3.将文件提交到Subversion
4.将svn修订号传递给其他平台以进行本地结帐(出于性能原因)
5.构建(C ++,Java)
6.测试

We have moved build system from CruiseControl to jenkins for a multi-platform product. This was a single monolithic job:
1. check for changes
2. update product build number in properties file
3. commit file to subversion
4. pass svn revision number to other platforms for local checkout (performance reasons)
5. build (C++, Java)
6. test

在Jenkins中,我们将构建和测试分为2个作业,构建触发了测试.所有平台构建都必须成功才能运行测试.我希望无论平台B上的构建失败如何,都可以在平台A上运行测试,但这是另一个问题.

In Jenkins, we have split the build and test into 2 jobs, build triggering the tests. All platform builds have to succeed for tests to run. I'd like tests on platform A to run regardless of build failure on platform B, but that's a different issue.

我现在要解决的问题是在构建阶段. Jenkins启动时,它将在作业开始时知道存储库的SVN_REVISION.在作业期间,我们在编译之前增加了内部版本号,这是我们需要传递给下游作业的svn修订版.我们需要确保在所有平台上签出相同的修订版,并且测试作业还签出相同的修订版.编译需要2-3个小时的时间,而测试大约需要7个小时,因此正常的情况下,在构建过程中会发生一些新的提交,这些提交将包含在测试作业中.在构建阶段,由于结帐速度不同,我们已经将提交包含在一个平台中,但没有包含在其他平台中.

The problem I'm trying to address now is for the build phase. When Jenkins starts, it knows the SVN_REVISION of the repository at start of job. We increment the build number before the compilation during the job and it is this svn revision we need to pass to downstream jobs. We need to ensure the same revision is checked out on all platforms and that the test job also checks out same revision. The compilation takes 2-3 hours and testing about 7 hours, so it is normal enough for some new commits to happen during the build that will be included in test job. We have also had commits during build phase that get included in one platform but not the others due to different speeds of checkout.

我们尝试了参数化触发器插件,该插件可以传递SVN_REVISION-作业启动时的修订,但不传递带有内部版本号的已修改文件的修订.在其他情况下,我们使用参数化触发器,它可以满足我们的需求.

We have tried Parameterized Trigger plugin which can pass SVN_REVISION - the revision at time job started, but does not pass the revision of modified file with build number. We use Parameterized Trigger in other cases and it does what we need.

我正在考虑将svn修订号添加到属性文件中的一件事.我可以从其他作业的属性文件中读取修订,假设文件没有更改,这可能会有风险. svn使用':'来分隔属性,即IIRC,其他属性使用'='作为key = value,因为我们还读取了要在Shell脚本中使用的属性.还有其他一些相关项目,因此当我回到办公室并设置一个沙箱(半天的工作)时,我将尝试使用此项目.

One thing I am thinking of doing to add svn revision number to properties file. I could read the revision from the property file in other jobs, assuming file has not been changed, which could be risky. svn uses ':' to separate property, IIRC, other properties use '=' for key=value as we also read properties to be used in shell scripts. There are other dependent projects, so I'll try this when I get back to office and set up a sandbox (half day's work).

有人有任何建议或意见吗?

Anyone got any recommendations or comments?

推荐答案

感谢本文和以下评论: https://itisatechiesworld.wordpress.com/jenkins-related-articles/jenkins-configuration/jenkins-passing-a-parameter-from-one-job-to-another/

Thanks to this post and the comments below: https://itisatechiesworld.wordpress.com/jenkins-related-articles/jenkins-configuration/jenkins-passing-a-parameter-from-one-job-to-another/

这是对我有用的答案:

  1. 获取参数化触发器插件(如何安装:管理Jenkins->管理插件->可用并检查参数化触发器插件"并安装,请注意我还安装了环境注射器插件",这也是必要的)
  2. 转到JOB_1并添加一个Post-Build操作(在其他项目上使用Trigger参数化的构建)
  3. 键入项目以构建JOB_2
  4. 添加参数(预定义参数)
  5. 在参数"框中键入以下内容:SVN_REV = $ {SVN_REVISION}
  6. 应用并保存
  7. 最重要的一点:您必须将此参数(SVN_REV)添加到JOB_2
  8. 转到并检查此构建已参数化"并添加字符串参数"
  9. 键入"SVN_REV"(必须为相同名称),并输入默认值1或其他任何值
  10. 它现在是一个环境变量,要访问它,您只需要%SVN_REV%
  11. 在构建步骤中,您可以编写echo%SVN_REV%,它将显示SVN_REVISION.
  1. Get the Parameterized Trigger Plugin (How to install: Manage Jenkins->Manage Plugins->Available and check "Parameterized Trigger Plugin" and install, note I also installed "Environment Injector Plugin", this may be necessary as well)
  2. Goto JOB_1 and add a Post-Build action (Trigger parameterized build on other projects)
  3. Type the project to build JOB_2
  4. Add Parameters (Predefined Parameters)
  5. Type the following in the Parameters box: SVN_REV=${SVN_REVISION}
  6. Apply and Save
  7. MOST IMPORTANT: YOU MUST ADD THIS PARAMETER (SVN_REV) to JOB_2
  8. Goto and check "This build is parameterized" and add a "String Parameter"
  9. Type "SVN_REV" (Must be same name) and put in a default value of 1 or anything
  10. It's now an environment variable, to access it, all you need is %SVN_REV%
  11. In your build step, you can write echo %SVN_REV% and it will display the SVN_REVISION.

简而言之(必须在两个作业中都指定参数) JOB_1 => SVN_REV = $ {SVN_REVISION}

In short (Parameter must be specified in BOTH jobs) JOB_1 => SVN_REV=${SVN_REVISION}

JOB_2 =>将SVN_REV添加为字符串参数,以访问类型%SVN_REV%

JOB_2 => Add SVN_REV as a String Parameter, to access type %SVN_REV%

这篇关于Jenkins-将更新的修订传递给下游工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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