Jenkins Multibranch Pipeline : 自动生成和管理Pipeline.

2024/10/18 09:16
阅读数 21

In the previous section a Jenkinsfile which could be checked into source control was implemented. This section covers the concept of Multibranch Pipelines which build on the Jenkinsfile foundation to provide more dynamic and automatic functionality in Jenkins.

在上一节中,实现了一个可以签入源代码控制的 Jenkinsfile。本节介绍了多分支管道的概念,它建立在 Jenkinsfile 基础之上,在 Jenkins 中提供更多动态和自动化功能。

Creating a Multibranch Pipeline

The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.

Multibranch Pipeline 项目类型使您能够为同一项目的不同分支实现不同的 Jenkinsfile。在 Multibranch Pipeline 项目中,Jenkins 会自动发现、管理和执行源代码控制中包含 Jenkinsfile 的分支的 Pipelines。

This eliminates the need for manual Pipeline creation and management.

这样就无需手动创建和管理 Pipeline。

To create a Multibranch Pipeline: Click New Item on Jenkins home page.

要创建 Multibranch Pipeline:单击 Jenkins 主页上的 New Item。

Enter a name for your Pipeline, select Multibranch Pipeline and click OK.

输入 Pipeline 的名称,选择 Multibranch Pipeline 并单击 OK。

Jenkins uses the name of the Pipeline to create directories on disk. Pipeline names which include spaces may uncover bugs in scripts which do not expect paths to contain spaces.

Jenkins 使用 Pipeline 的名称在磁盘上创建目录。包含空格的管道名称可能会发现脚本中的错误,这些脚本不希望路径包含空格。

Add a Branch Source (for example, Git) and enter the location of the repository.

添加 Branch Source(例如 Git)并输入存储库的位置。

Save the Multibranch Pipeline project.

Upon Save, Jenkins automatically scans the designated repository and creates appropriate items for each branch in the repository which contains a Jenkinsfile.

保存 Multibranch Pipeline 工程。

保存后,Jenkins 会自动扫描指定的存储库,并为存储库中包含 Jenkinsfile 的每个分支创建适当的项目。

By default, Jenkins will not automatically re-index the repository for branch additions or deletions (unless using an Organization Folder), so it is often useful to configure a Multibranch Pipeline to periodically re-index in the configuration:

默认情况下,Jenkins 不会自动为仓库的添加或删除重新索引(除非使用组织文件夹),因此将 Multibranch Pipeline 配置为定期在配置中重新索引通常很有用:

Additional Environment Variables

Multibranch Pipelines expose additional information about the branch being built through the env global variable, such as:

Multibranch Pipelines 通过 env 全局变量公开有关正在构建的分支的其他信息,例如:

BRANCH_NAME

Name of the branch for which this Pipeline is executing, for example master.

CHANGE_ID

An identifier corresponding to some kind of change request, such as a pull request number

Additional environment variables are listed in the Global Variable Reference.

其他环境变量在 Global Variable Reference 中列出。https://www.jenkins.io/doc/book/pipeline/getting-started/#global-variable-reference#

Supporting Pull Requests

Multibranch Pipelines can be used for validating pull/change requests with the appropriate plugin. This functionality is provided by the following plugins:

Multibranch Pipelines 可用于通过适当的插件验证 pull/change 请求。此功能由以下插件提供:

  • GitHub Branch Source
  • Bitbucket Branch Source
  • GitLab Branch Source
  • Gitea
  • Tuleap Git Branch Source
  • AWS CodeCommit Jobs
  • DAGsHub Branch Source

Please consult their documentation for further information on how to use those plugins.

有关如何使用这些插件的更多信息,请参阅他们的文档。

Using Organization Folders

Organization Folders enable Jenkins to monitor an entire GitHub Organization, Bitbucket Team/Project, GitLab organization, or Gitea organization and automatically create new Multibranch Pipelines for repositories which contain branches and pull requests containing a Jenkinsfile.

组织文件夹使 Jenkins 能够监控整个 GitHub 组织、Bitbucket 团队/项目、GitLab 组织或 Gitea 组织,并自动为包含分支和拉取请求的存储库创建新的多分支管道。

Organization folders are implemented for:

  • GitHub in the GitHub Branch Source plugin
  • Bitbucket in the Bitbucket Branch Source plugin
  • GitLab in the GitLab Branch Source plugin
  • Gitea in the Gitea plugin

原文链接:

https://www.jenkins.io/doc/book/pipeline/multibranch/#branches-and-pull-requests

本文分享自微信公众号 - DevOps云学堂(idevopsvip)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部