使用相同git分支名称关联的2个项目中的工件的管道 [英] Pipeline to use artifacts from 2 projects associated by the same git branch name

查看:197
本文介绍了使用相同git分支名称关联的2个项目中的工件的管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的公司正在评估jenkins 2.71,尤其是管道 blue ocean 插件.我们还已经测试了 GoCD ,并且像 GoCD 一样,我们需要管道自动从其他2个管道中获取工件的方法(获取每个工件的最后成功结果),在我们的案例中.

我们有以下初始管道(构建和运行测试),它们反映了2个项目:

  • 前端,大​​约15分钟
  • 后端,大​​约10分钟

我创建了一个名为 configure 的管道(大约1分钟),例如一个名为 customer-name 的参数,该参数接收后端和前端文件并将它们放在一起,然后应用特定于客户的特定配置和自定义项,并生成可部署的工件.除了客户名"之外,我还可以并行执行此工作,以一次为每个客户创建所有工件,并在不同目录中进行分隔.

下一个管道是将它们部署在针对每个客户分开的不同测试服务器上.这也可能是相同的 configure 管道的一部分,我们仍然必须看看如何将所有东西放到jenkins中.

理想情况下,我需要 configure 管道在每次前端或后端成功后自动触发(或按需),并从这2个中获得最后成功的工件作为输入管道,而不仅仅是成功完成最后一次构建,我们还需要 git分支名称的依赖.

例如我们有:

后端分支:

  • 主人
  • 版本/2017.2

前端分支机构

:
  • 主人
  • 版本/2017.2

在管道编辑器中,我找到了一个 Build Triggers 选项,并将其设置如下:在构建其他项目之后进行构建> 要观看的项目:前端,后端>仅在构建稳定的情况下检查 Trigger ,或者在充满故障的我的测试环境中检查 Trigger更好,即使构建不稳定也可以.

进一步搜索后,我发现复制工件插件

但是现在最大的问题是,如何从具有相同git分支名称的管道中获取最后成功的工件?

因为我们不想混用一个后端版本为"release/2017.2"且前端为"master"的后端版本,它必须找到具有相同关系或参数或您要称为它的任何最终成功版本,在本例中,关联为git分支名称.

有可能实现这一目标吗?如果是,怎么办?

复制工件插件似乎可以在自由式项目中工作.它可以在管道中工作吗?这也是一个问题...

谢谢

解决方案

是的,Copy Artifact插件可以在自由式项目和管道项目中使用;管道使用我在注释中引用的copyArtifact函数.请注意,如果转到流水线语法"链接,则它是隐藏的:您必须首先从下拉列表中选择"step: General Build Step",然后它将为您提供复制工件"流水线命令构建器.

我将假设您的frontendbackend项目是作为多分支管道构建的,因为这可能最容易维护,因此您不必为每个发行版都继续创建新项目. .您可以通过引用<project name>/<branch name>从其他项目中引用这些项目(有时我不得不将/替换为%2f,我认为主要是在自由式项目中).然后,您可以将configure项目设置为参数化构建(管道或自由样式),例如使用字符串参数PROJECT_BRANCH_NAME.然后在前端/后端项目管道脚本中添加以下内容,以触发configure项目

的构建

build job: 'configure', parameters: [[$class: 'StringParameterValue', name: 'PROJECT_BRANCH_NAME', value: ${env.BRANCH_NAME}]]

然后,您应该能够在复制工件时使configure项目引用frontend/%PROJECT_BRANCH_NAME%backend/%PROJECT_BRANCH_NAME%(或管道脚本中的${env.PROJECT_BRANCH_NAME}).

还有,您为什么要专门评估Jenkins 2.7? 2.7已有一年的历史了,此后又发布了一些LTS新版本.我建议保持合理的最新状态,除非您知道要使用2.7的特定原因.

the company where I work for is evaluating jenkins 2.71, in particular the pipeline and blue ocean plugins. We already tested also GoCD and we need, as in GoCD, a way for a pipeline to automatically fetch the artifacts from 2 other pipelines (taking the last successful result of each one of them), here our case.

We have these initial pipelines (build & run tests), which reflect 2 projects:

  • frontend, ~ 15 minutes
  • backend, ~10 minutes

I created a pipeline called configure (~1 minute), with e.g. a parameter called customer-name, which takes backend and frontend files and puts them together, then applies specific customer specific configurations and customizations and produces deployable artifacts. Instead of "customer-name" I could also parallelize this job to create all the artifacts for each customer at once, separated in different directories.

The next pipeline would be to deploy them on different test servers separated for each customer. This could be also part of the same configure pipeline, we still have to see how to put things together in jenkins...

Ideally, I need configure pipeline to be triggered automatically (or also on demand) after each frontend or backend success and take as input the last successful artifacts from these 2 pipelines, but not just having the last successful build, we need as dependency the git branch name.

E.g. we have:

backend branches:

  • master
  • release/2017.2

frontend braches:

  • master
  • release/2017.2

In the pipeline editor, I found a Build Triggers option and set it as follows: Build after other projects are built > Projects to watch: frontend, backend > Check Trigger only if build is stable or better in my test environment full of failures Trigger even if the build is unstable.

Searching further, I found Copy Artifact Plugin

But now the big question, how to fetch the last successful artifacts from these pipelines with the same git branch name?

Because we don't want to mix e.g. a backend build of "release/2017.2" with frontend "master", it has to find as the last successful build having the same relationship or parameter or whatever you wanna call it, in our case the association is the git branch name.

Is it possible to achieve this? If yes, how?

The copy artifact plugin seems to work in a freestyle project. Would it work in a pipeline? That's also a concern...

Thanks

解决方案

Yes, the Copy Artifact plugin does work in both freestyle and pipeline projects; pipeline uses the copyArtifact function that I referenced in my comment. Note that if you go to the Pipeline Syntax link, it's kind of hidden: you have to first select "step: General Build Step" from the drop-down, then it will give you the Copy Artifact pipeline command builder.

I'm going to assume that your frontend and backend projects are built as multi-branch pipelines, as that would probably be easiest to maintain so that you don't have to keep creating new projects for every release. You can reference these projects from other projects by referencing <project name>/<branch name> (sometimes I've had to replace the / with %2f instead, I think mostly on freestyle projects). You could then set up your configure project as a parameterized build (either pipeline or freestyle), say with a string parameter of PROJECT_BRANCH_NAME. Then put in the following in your frontend/backend project pipeline scripts to trigger a build of your configure project

build job: 'configure', parameters: [[$class: 'StringParameterValue', name: 'PROJECT_BRANCH_NAME', value: ${env.BRANCH_NAME}]]

Then you should just be able to make your configure project reference the frontend/%PROJECT_BRANCH_NAME% and backend/%PROJECT_BRANCH_NAME% (or ${env.PROJECT_BRANCH_NAME} in a pipeline script) when copying the artifacts.

Also, is there a particular reason why you're evaluating specifically Jenkins 2.7? 2.7 is a year old now, and there have been a few new LTS releases since then. I'd recommend staying reasonably up-to-date unless you know there's a specific reason you want 2.7.

这篇关于使用相同git分支名称关联的2个项目中的工件的管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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