简体   繁体   English

如何使用具有相关git存储库和多个分支的Jenkins作业

[英]How to use Jenkins job(s) with dependent git repositories and multiple branches

We have 2 git repositories, Platform and US (we have other geo-specific ones as well which is why they are split, but they are not necessarily relevant here). 我们有2个git存储库,分别是Platform和US(我们还有其他特定于地理位置的存储库,这就是为什么要拆分它们的原因,但它们在此处不一定相关)。 US depends on Platform. 美国取决于平台。

We are using git-flow (meaning new features are in their own branches like feature/some-product , develop branch is somewhat more stable and represents QA-ready builds, master branch is stable and for releases). 我们正在使用git-flow(这意味着新功能在它们自己的分支中,例如feature/some-productdevelop分支在某种程度上更稳定,并且代表可进行QA的构建, master分支是稳定的并且可以发布)。 (If a feature has both Platform and US parts, there will be a branch in each with the same name.) We decided that the Jenkins jobs for the features should not run mvn deploy because we don't want to publish them to the snapshot repository and probably shouldn't run mvn install because we don't want a different feature branch to grab it from Jenkins's local repo (this we are less sure about though). (如果某个功能同时具有Platform和US部分,则每个功能中都将有一个具有相同名称的分支。)我们决定,该功能的Jenkins作业不应运行mvn deploy因为我们不想将它们发布到快照中存储库,可能不应该运行mvn install因为我们不希望其他功能分支从Jenkins的本地存储库中获取它(尽管我们不太确定)。 We believe they should only make sure everything compiles and that the unit tests pass ( mvn verify ). 我们相信他们只应确保所有内容都能编译并且单元测试通过( mvn verify )。

This is where the problem comes in, because these are separate git repositories and we are not doing anything with the compiled jar ( install or deploy ), 这就是问题所在,因为它们是单独的git存储库,而我们对已编译的jar( installdeploy )不做任何事情,

  • how can we safely expose the compiled jars from the Platform job to the US without exposing them to other developers or jobs (or is this even a concern is only doing mvn install ) or 我们如何才能安全地将已编译的jar从Platform作业公开给美国,而又不将它们暴露给其他开发人员或工作(或者甚至只是在执行mvn install引起的担忧),或者
  • how can one Jenkins job build Platform and US for a specific branch together? 詹金斯(Jenkins)的工作如何为特定分支机构共同构建Platform和US?

If we only have a single actively developed branch (or we were using subversion) this would not be an issue. 如果我们只有一个主动开发的分支(或者我们正在使用Subversion),那么这将不是问题。

Some ideas we have (and concerns with each) 我们有一些想法 (以及每个想法

  • For feature branches use a different version (eg, 8.1.0-SNAPSHOT-some-product ). 对于功能分支,请使用其他版本(例如8.1.0-SNAPSHOT-some-product )。
    • This seems like a lot of work for every feature branch. 每个功能分支似乎都要做很多工作。
    • It seems like it'd clog up the local repo with "stale" jars, and we would need to worry about purging them. 似乎它会用“陈旧”的罐子堵塞本地存储库,我们需要担心清除它们。
  • Somehow use git submodule to checkout Platform's and US's feature/some-product and either use mvn verify --reactor or a simple pom file with the top level projects as modules. 以某种方式使用git submodule来检出Platform和US的feature/some-product并使用mvn verify --reactor或将顶层项目作为模块的简单pom文件。
    • How to make Jenkins add the submodules? 如何使Jenkins添加子模块?
    • If the submodules were already there, there would need to be a whole git repo for this, which seems redundant. 如果子模块已经存在,则需要一个完整的git repo,这似乎是多余的。
    • --reactor doesn't work always. --reactor并不总是起作用。
    • How to supply the pom file? 如何提供pom文件?
  • Just do mvn install . 只需执行mvn install
    • feature/other-thing may only be on US, so after Platform feature/some-product publishes to Jenkins local repository (which may be very different from Platform develop , which US feature/other-thing would be built against normally), it would (We think) cause US feature/other-thing to fail (or pass!) in a false sense (supposing that if it were compiled against Platform develop it could possibly get a different result). feature/other-thing可能仅在美国销售,因此在平台feature/some-product发布到Jenkins本地存储库(可能与平台develop (美国feature/other-thing通常会针对该平台进行develop非常不同)之后) (我们认为)会导致美国feature/other-thing在错误的意义上失败(或通过!)(假设如果针对平台develop进行编译,则可能会得到不同的结果)。

I have not had to address this issue personally.... here is my thoughts on how I would look at the issue: 我不必亲自解决此问题。...这是我对问题的看法:

If you MUST only have one job for both branches (a bad idea), you can use parameterized build plugin to pass in the text string "US" or "Platform" and have logic in a shell script that will check out the relevant repo's branch. 如果两个分支都只能有一份工作(一个坏主意),则可以使用参数化的构建插件来传递文本字符串“ US”或“ Platform”,并在Shell脚本中包含逻辑,以检查出相关仓库的分支。

HOWEVER, this eliminates the ability to have repo polling kickoff the build. 但是,这消除了回购轮询启动构建的能力。 You would have to set up a build schedule on a cron and you would get a new build no matter what, even if the repo hasn't changed (unless your batch / shell script is smart enough to check for changes). 您将必须在cron上设置构建时间表,并且无论回购没有变化,无论如何都将获得新的构建(除非您的批处理/ shell脚本足够聪明以检查更改)。

I don't see any reason NOT to have two separate Jenkins Jobs, one for each branch. 我看不出没有两个单独的詹金斯·乔布斯的理由,每个分支一个。

If one job needs access to the .jars (aka the build artifacts) then you can always reference the artifacts of any other jar from the job's "LATEST" URL on the jenkins server. 如果一个作业需要访问.jar(也称为构建工件),则您始终可以从jenkins服务器上作业的“最新” URL引用任何其他jar的工件。 Be sure the jobs specify what artifacts need to get archived. 确保作业指定需要归档的工件。

The way I ended up solving this is using the maven versions plugin. 我最终解决此问题的方法是使用maven版本插件。 I had to make sure all the modules were managed dependencies in the top-level project, but that may have been a different issue. 我必须确保所有模块都是顶级项目中的托管依赖项,但这可能是一个不同的问题。 Also, I am sure of this, the US project will need to explicitly declare its version even if it is the same as the parent. 此外, 相信这一点,美国项目将需要显式声明它的版本,即使是相同的父。

They both poll git but the Platform job also triggers US if it built successfully. 他们都轮询git,但是Platform工作如果成功构建,也会触发US。

The way the versions plugin works will require you to do this in two steps. 版本插件的工作方式需要您分两个步骤进行。 Add 2 "Invoke top-level Maven targets" in the job, the second is the clean deploy . 在工作中添加2个“调用顶级Maven目标”,第二个是clean deploy The first is a little different for the Platform and US. 对于平台和美国而言,第一个有点不同。

Platform: mvn versions:set -DnewVersion=yourBranchName-${project.version} . 平台: mvn versions:set -DnewVersion=yourBranchName-${project.version}

US: mvn versions:update-parent -DparentVersion=yourBranchName-${project.version} versions:set -DnewVersion=yourBranchName-${project.version} 美国: mvn versions:update-parent -DparentVersion=yourBranchName-${project.version} versions:set -DnewVersion=yourBranchName-${project.version}

If the branch only exists on the US repository, then obviously don't make the Platform one, and the US one is the same command as what the Platform one's would have been. 如果该分支仅存在于美国存储库中,那么显然不要将其作为平台,而美国将与该平台相同。

One final issue I ran into was originally I had the new version as ${project.version}-yourBranchName but the issue here was that the repository the job was deploying to only accepted snapshots and because the version didn't end in -SNAPSHOT it gave error code 400. 我遇到的最后一个问题最初是我的新版本为${project.version}-yourBranchName但是这里的问题是作业正在部署到仅接受快照的存储库,并且因为该版本未以-SNAPSHOT结尾输入错误代码400。

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

相关问题 如何在一个 bndtools 工作区中使用多个 git 存储库 - How to use multiple git repositories in one bndtools workspace 建立SNAPSHOT依赖项时如何触发具有多个分支的jenkins maven作业? - How to trigger jenkins maven job with multiple branches when a SNAPSHOT dependency is built? 如何在同一台Windows计算机上使用具有相同帐户的多个存储库使用GIT - How can I use GIT with multiple repositories with the same account on the same windows machine Jenkins:如何为多个Java项目创建Job? - Jenkins: How to create a Job for multiple Java Projects? 如何使用具有相同存储库的多个数据源类型? - How to use multiple datasources types with the same repositories? 在多个分支中使用分支 - use branch in multiple branches gradle build with subprojects, git feature branches and jenkins multibranch pipeline: 如何只在受影响的子项目上运行测试 - gradle build with subprojects, git feature branches and jenkins multibranch pipeline: how to only run tests on affected subprojects Jenkins作业会自动构建所有可用的SVN分支 - Jenkins job automatically building all SVN branches available 多个项目的通用jenkins工作 - Generic jenkins job for multiple projects Jenkins 有多个 Maven 目标的工作 - Jenkins job with multiple maven goals
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM