简体   繁体   English

Jenkins 来自版本控制 (Bitbucket) 的多分支管道 - 我可以为特定分支指定规则吗?

[英]Jenkins Multibranch Pipeline from Version Control (Bitbucket) - can I specify rules for specific branches?

I am currently creating a multibranch pipeline from BitBucket, which will build all branches automatically.我目前正在从 BitBucket 创建一个多分支管道,它将自动构建所有分支。 That would be extremely helpful for pull requests and overall save a lot of time.这对于拉取请求非常有帮助,并且总体上可以节省大量时间。 However this specific project is a little bit different - it is a web application and it is built with 2 different Jenkins jobs:然而,这个特定的项目有点不同 - 它是一个 web 应用程序,它由 2 个不同的 Jenkins 作业构建:

Job 1: Checkout files from Version Control (Subversion and Git) and if successfull trigger Job 2 (from the job configuration).作业 1:从版本控制(Subversion 和 Git)签出文件,如果成功触发作业 2(从作业配置)。

Job 2: Transfer the files from Job 1 to node, and execute the deployment scripts.作业 2:将作业 1 中的文件传输到节点,并执行部署脚本。 There is a lot of extra configuration in the job, which I do not need to explain.工作中有很多额外的配置,我不需要解释。 If this job is successful, the web application is deployed.如果此作业成功,则部署 web 应用程序。

However, how the multibranch pipeline works is that it points to the Jenkinsfile of each branch (which starts Job 1) and builds that.但是,多分支管道的工作方式是它指向每个分支的 Jenkinsfile(它启动 Job 1)并构建它。 Everytime is successful, however it doesn't trigger Job 2. Also in BitBucket it shows up as successfull build for all branches, because it only looks for this specific job.每次都成功,但它不会触发作业 2。同样在 BitBucket 中,它显示为所有分支的成功构建,因为它只查找此特定作业。

Is there a way I can make individual rules for the branch jobs, so that they trigger another job, and that BitBucket looks for that job as a reference if a build has passed or failed?有没有办法可以为分支作业制定单独的规则,以便它们触发另一个作业,如果构建通过或失败,BitBucket 会查找该作业作为参考? I would very much not like to combine the whole functionality in a single JenkinsFile, because it would be a massive change.我非常不想将整个功能组合在一个 JenkinsFile 中,因为这将是一个巨大的变化。 Thank you.谢谢你。

It is not clear what actions you do in your second Job to understand if it is common for all the jobs or it is very different for each branch.目前尚不清楚您在第二份工作中执行了哪些操作,以了解是所有工作都通用还是每个分支都非常不同。

First with the assumption, your second job is common for all the branches, you can have a Jenkins file in each branch which triggers the common job (based on another jenkins file which is in a common location) in it.首先假设,您的第二个工作对所有分支都是通用的,您可以在每个分支中有一个 Jenkins 文件,该文件会触发公共工作(基于另一个位于公共位置的 jenkins 文件)。

Second, if the functionality is different for each branch, what I would suggest is come up with a generic functions and try passing parameters based on the requirement of each branch in the first Jenkins file.其次,如果每个分支的功能不同,我建议提出一个通用函数,并尝试根据第一个 Jenkins 文件中每个分支的要求传递参数。

This is just an idea.这只是一个想法。 If you can explain little bit more about the second jobs behaviour, I might be able to throw some more ideas to help you.如果你能解释更多关于第二份工作的行为,我可能会提出更多的想法来帮助你。

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

相关问题 Jenkins 多分支管道:Select 仅构建 2 个特定分支 - Jenkins MultiBranch Pipeline: Select to build only 2 specific branches Jenkins 多分支管道 - 创建 PullRequest 时不会从 Bitbucket 触发扫描 - Jenkins Multibranch Pipeline - scan is not triggered from Bitbucket when a PullRequest is created 我如何使用 Jenkins 和 Pipeline Multibranch 插件跨分支拥有唯一的内部版本号 - How can I have unique build numbers across branches with Jenkins & the Pipeline Multibranch Plugin Jenkins-MultiBranch管道:无法从源获取分支 - Jenkins - MultiBranch Pipeline : Could not fetch branches from source 防止 Jenkins 多分支管道触发新分支的构建 - Prevent Jenkins multibranch pipeline from triggering builds for new branches Jenkins 多分支管道在不相关的分支上触发管道 - Jenkins multibranch pipeline triggers pipeline on unrelated branches 获取 Jenkins 多分支管道中的分支列表 - Get list of branches in Jenkins multibranch pipeline 如何在 Jenkins Multibranch Pipeline 插件中从 pom 获取 artifactId 和 version - How to get artifactId and version from pom in a Jenkins Multibranch Pipeline plugin 多分支 Jenkins 管道停止扫描所有分支中的 Jenkins 文件 - Multibranch Jenkins pipeline stop scanning for Jenkins file in all branches Jenkins 从另一个多分支管道构建多分支管道 - Jenkins build multibranch pipeline from another multibranch pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM