简体   繁体   English

Jenkins Build管道和并行作业的问题

[英]Problems with Jenkins Build pipeline and parallel jobs

Background 背景

I am using Jenkins with the Build Pipeline plugin to build some fairly complicated projects that require multiple compilation steps: 我将Jenkins与Build Pipeline插件一起使用来构建一些相当复杂的项目,这些项目需要多个编译步骤:

  1. Build source RPM. 构建源RPM。
  2. Build binary RPM (this is performed twice, once for each platform). 构建二进制RPM(此操作执行两次,每个平台执行一次)。
  3. Deploy to YUM repository. 部署到YUM存储库。

My strategy for solving build requirements involves splitting the common work into parameterized jobs that can be reused across projects and branches, with each job representing one stage in the pipeline. 我解决构建要求的策略包括将普通工作分成参数化的工作,这些工作可以在项目和分支之间重复使用,每个工作代表管道中的一个阶段。 Each stage is triggered with parameters, and build artifacts passed along to the next job in the pipeline. 每个阶段都由参数触发,并生成工件传递到管道中的下一个作业。 However, I'm having some trouble with this strategy, and could really use some tips on how to go about solving this problem in the most elegant and flexible way possible. 但是,我在使用此策略时遇到了麻烦,确实可以使用一些技巧来尽可能以最优雅,最灵活的方式解决此问题。

To be more specific, there are two common libraries, which are shared by other projects (but not all projects). 更具体地说,有两个公共库,它们由其他项目(但不是所有项目)共享。 The libraries are built differently from the dependent projects, but it should not be necessary to specify in Jenkins what the dependent projects are. 库的构建与从属项目不同,但是不必在詹金斯中指定什么是从属项目。

There are multiple branches, the master branch (rebuilt nightly), the develop branch (polled for changes), feature branches (also polled), and release branches (polled, but built for release). 有多个分支,主分支(每晚重建),开发分支(轮询更改),功能分支(也轮询)和发布分支(轮询,但为发布而构建)。 The branches are built the same way across multiple projects. 在多个项目中以相同的方式构建分支。

We create multiple repositories every month, and whilst it is feasible to expect a little setup for a new project, generally we want this to be as simple and automated as possible. 我们每个月都会创建多个存储库,虽然可以期望为新项目进行一些设置,但总的来说,我们希望它尽可能简单和自动化。

The Problems 问题所在

  1. I have many projects with multiple branches, and I do not wish to build all branches or even all projects in the same way. 我有许多具有多个分支的项目,并且我不希望以相同的方式构建所有分支甚至所有项目。 Because most of the build steps are similar I can turn these common steps into parameterized build jobs, and get each job to trigger the next in the chain, passing parameters and build artifacts along the chain. 因为大多数构建步骤都是相似的,所以我可以将这些通用步骤转换为参数化的构建作业,并让每个作业触发链中的下一个,沿着链传递参数和构建工件。 However, this falls apart if one of the steps needs to be skipped, because I don't know of a way to conditionally skip a build step. 但是,如果需要跳过其中一个步骤,这会分崩离析,因为我不知道有条件地跳过构建步骤的方法。 This implies I would need to copy the build jobs so that I can customise them for each pipeline, resulting in a very large number of build jobs. 这意味着我将需要复制构建作业,以便可以为每个管道自定义它们,从而导致大量的构建作业。 I could use a combination of plugins to create a job generator (eg. dsl flow, dsl job, etc), and hide as much as possible from the users, but what's the most elegant Jenkins solution to this? 我可以使用插件的组合来创建作业生成器(例如dsl流,dsl作业等),并向用户尽可能多地隐藏,但是最完美的Jenkins解决方案是什么? Are there any plugins, or examples that I might have missed? 有没有我可能错过的插件或示例? What's your experience of doing this? 您的经验是什么?

  2. Because step 2 can be split into two jobs that can be run in parallel, this introduces a complexity that is causing me problems with my pipeline. 由于步骤2可以分为两个可以并行运行的作业,因此引入了复杂性,这使我的管道出现问题。 My first attempt would trigger a parameterized build job twice with different parameters, and then join the jobs afterwards using the join plugin, but it was beginning to look like it would be complicated to copy in the build artifacts from the two upstream jobs. 我的第一次尝试将使用不同的参数触发两次参数化的构建作业,然后再使用join插件将其加入作业,但是从两个上游作业中复制构建工件看起来似乎很复杂。 This is significant, because I need the build artifacts from both jobs for stage 3. What's the most elegant solution to join parallel jobs and copy artifacts from them all? 这很重要,因为在阶段3中,我需要这两个作业都需要构建构件。什么是结合并行作业并从所有作业中复制构件的最佳解决方案? Are there any examples that I might have missed? 有没有我可能会错过的例子?

  3. I need to combine test results generated from both of the jobs in stage 2, and copy them to the job that triggers the build. 我需要合并从阶段2的两个作业生成的测试结果,并将它们复制到触发构建的作业中。 What's the best way to handle this? 处理此问题的最佳方法是什么?

I'm happy to read articles, presentations, technical articles, reference documentation, write scripts and whatever else necessary to make this work nicely, but I'm not a Jenkins expert. 我很高兴阅读文章,演示文稿,技术文章,参考文档,编写脚本以及使它正常运行所需的其他任何东西,但我不是詹金斯专家。 If anyone can give me some advice on these 3 problems then that would be helpful. 如果有人可以针对这3个问题给我一些建议,那将有所帮助。 Additionally, I would appreciate any constructive advice on how to get the best out of pipeline CI builds in Jenkins, if relevant. 此外,如果有相关的建议,我将对如何在Jenkins中充分利用管道CI的建设性建议表示赞赏。

For the first point, the Job Generator plugin I wrote has been developed to address this use case. 对于第一点,我编写的Job Generator插件已经开发出来,可以解决这种用例。 You can find more info on the wiki page of Job Generator . 您可以在Job Generator的Wiki页面上找到更多信息。 There is also the same type of plugin with a different approach (job generator as a build step), it is called Jobcopy Builder . 还有一种具有不同方法(工作生成器作为构建步骤)的相同类型的插件,称为Jobcopy Builder The other approaches you mentioned require some kind of DSL and can be a good choice too. 您提到的其他方法需要某种DSL,也可能是不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM