如何有条件地构建其他项目? [英] How to conditionally build other projects?

查看:25
本文介绍了如何有条件地构建其他项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的 Jenkins 工作,负责构建、单元测试和打包 Web 应用程序.根据情况,一旦这项工作完成,我想做不同的事情.我还没有找到一种可重复使用/可维护的方法来做到这一点.真的是这样还​​是我遗漏了什么?

I have a fairly complicated Jenkins job that builds, unit tests and packages a web application. Depending on the situation, I would like to do different things once this job completes. I have not found a re-usable/maintainable way to do this. Is that really the case or am I missing something?

完成复杂工作后我想要的选项:

The options I would like to have once my complicated job completes:

  1. 什么都不做

  1. Do nothing

开始我的低风险变更构建管道:

Start my low-risk-change build pipeline:

  • 将我的 WAR 文件复制到我的工件存储库
  • 部署到生产环境

启动我的高风险变更构建管道:

Start my high-risk-change build pipeline:

  • 将我的 WAR 文件复制到我的工件存储库
  • 部署以进行测试
  • 运行验收测试
  • 部署到生产环境

我还没有找到一种简单的方法来做到这一点.最简单但不太易于维护的方法是制作三个独立的作业,每个作业都启动下游构建.这种方法让我感到害怕有几个原因,包括必须在三个地方而不是一个地方进行更改.此外,许多下游工作也几乎相同.唯一的区别是他们调用哪些下游作业.工作的激增似乎会导致无法维护的混乱.

I have not found an easy way to do this. The simplest, but not very maintainable approach would be to make three separate jobs, each of which kicks off a downstream build. This approach scares me for a few reasons including the fact that changes would have to be made in three places instead of one. In addition, many of the downstream jobs are also nearly identical. The only difference is which downstream jobs they call. The proliferation of jobs seems like it would lead to an un-maintainable mess.

我曾考虑使用多种方法将其作为一项工作,但到目前为止都没有奏效:

I have looked at using several approaches to keep this as one job, but none have worked so far:

  1. 使作业成为多配置项目 (https://wiki.jenkins-ci.org/display/JENKINS/Building+a+matrix+project).这提供了一种使用参数注入作业的方法.我还没有找到让构建其他项目"步骤响应参数的方法.

  1. Make the job a multi-configuration project (https://wiki.jenkins-ci.org/display/JENKINS/Building+a+matrix+project). This provides a way to inject the job with a parameter. I have not found a way to make the "build other projects" step respond to a parameter.

使用参数化触发器插件(https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin).此插件可让您根据某些触发器触发下游作业.不过,触发器似乎过于严格.它们都基于构建的状态,而不是任意变量.我没有看到此处提供的任何选项适用于我的用例.

Use the Parameterized-Trigger plugin (https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin). This plugin lets you trigger downstream-jobs based on certain triggers. The triggers appear to be too restrictive though. They're all based on the state of the build, not arbitrary variables. I don't see any option provided here that would work for my use case.

使用灵活发布插件(https://wiki.jenkins-ci.org/display/JENKINS/Flexible+Publish+Plugin).这个插件与参数化触发器插件有相反的问题.它可以检查许多有用的条件,但它看起来不像可以开始构建另一个项目.它的操作仅限于发布类型的活动.

Use the Flexible Publish plugin (https://wiki.jenkins-ci.org/display/JENKINS/Flexible+Publish+Plugin). This plugin has the opposite problem as the parameterized-trigger plugin. It has many useful conditions it can check, but it doesn't look like it can start building another project. Its actions are limited to publishing type activities.

使用灵活发布 + 任何构建步骤插件 (https://wiki.jenkins-ci.org/display/JENKINS/Any+Build+Step+Plugin).Any Build Step 插件允许灵活发布插件可以使用任何构建操作.虽然激活此插件后可以使用更多操作,但这些操作不包括构建其他项目".

Use Flexible Publish + Any Build Step plugin (https://wiki.jenkins-ci.org/display/JENKINS/Any+Build+Step+Plugin). The Any Build Step plugin allows making any build action available to the Flexible Publish plugin. While more actions were made available once this plugin was activated, those actions didn't include "build other projects."

真的没有一种简单的方法可以做到这一点吗?我很惊讶我没有找到它,更惊讶的是我没有真正看到其他人试图这样做?我在做一些不寻常的事情吗?有什么明显的我遗漏了吗?

Is there really not an easy way to do this? I'm surprised that I haven't found it and even more surprised that I haven't really seen any one else trying to do this? Am I doing something unusual? Is there something obvious that I am missing?

推荐答案

如果我理解正确,您应该可以按照以下步骤进行操作:

If I understood it correct you should be able to do this by following these Steps:

  1. 第一个构建步骤:
  1. First Build Step:
  1. 做日常工作.就您而言:网络应用的构建、单元测试和打包
  2. 根据结果让它创建一个具有特定名称的文件.
  3. 这意味着如果您希望在之后运行低风险更改,请创建一个文件 low-risk.prop

  • 第二个构建步骤:

  • Second Build Step:

    1. 在其他项目上创建触发器/调用构建 参数化触发器的步骤插入.
    2. 要构建的项目字段中输入您的低风险工作的名称
    3. 点击:添加参数
    4. 选择:来自属性文件的参数
    5. 使用文件中的属性字段
    6. 中输入low-risk.prop
    7. 启用如果缺少任何文件则不触发
    1. Create a Trigger/call builds on other projects Step from the Parameterized-Trigger plugin.
    2. Entery the name of your low-risk job into the Projects to build field
    3. Click on: Add Parameter
    4. Choose: Parameters from properties File
    5. Enter low-risk.prop into the Use properties from file Field
    6. Enable Don't trigger if any files are missing

  • 第三个构建步骤:

  • Third Build Step:

    1. 检查是否存在 low-risk.prop 文件
    2. 删除文件

  • 对高风险工作做同样的事情

    Do the same for the high-risk job

    现在您应该有以下设置:

    • 如果在第一个构建步骤中出现名为 low-risk.prop 的文件,则将启动低风险作业
    • 如果在第一个构建步骤中出现名为 high-risk.prop 的文件,则将启动高风险作业
    • 如果没有 .prop 文件什么都不会发生

    这就是您想要实现的目标.不是吗?

    And that's what you wanted to achieve. Isn't it?

    这篇关于如何有条件地构建其他项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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