如何从 Jenkins 中的构建中排除 git branch
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21314632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exclude git branch from building in Jenkins
提问by Carneiro
Here is my current Jenkins setup for a project:
这是我当前为项目设置的 Jenkins:
- one job runs alldevelopment branches
- one job runs all pull requests
- one job runs only the masterbranch
- one job makes the automated release only when master passes
- 一项工作运行所有开发分支
- 一项工作运行所有拉取请求
- 一项工作只运行主分支
- 一项工作只有在主人通过时才会自动发布
This setup allows me to have continuous automated delivery as well as constant feedback during development. The first 3 jobs also run all tests and coverage reports.
这种设置使我能够在开发过程中进行持续的自动化交付以及持续的反馈。前 3 个作业还运行所有测试和覆盖率报告。
The problem is that I could not find a way to exclude the master branch from the "all development branches" job. It unnecessarily builds master twice every time I merge a pull-request.
问题是我找不到从“所有开发分支”工作中排除主分支的方法。每次我合并一个拉取请求时,它都会不必要地构建两次 master。
Does anybody know how to exclude one branch from the job in Jenkins ?
有人知道如何从 Jenkins 的工作中排除一个分支吗?
ps: I am using the Git and the Github plugins. My project is stored on Github.
ps:我正在使用 Git 和 Github 插件。我的项目存储在 Github 上。
回答by kyanny
You can choose "Inverse" strategy for targeting branches to build.
您可以选择“反向”策略来定位要构建的分支。
Check out Jenkins job configuration,
查看 Jenkins 作业配置,
- "Source Code Management" section (choose "Git")
- Additional Behaviours
- click "Add" button
- choose "Strategy for choosing what to build"
- select "Inverse" strategy in combo box.
- “源代码管理”部分(选择“Git”)
- 附加行为
- 点击“添加”按钮
- 选择“选择构建内容的策略”
- 在组合框中选择“反向”策略。
(Don't forget to fill in "Branches to build" text field by "master")
(不要忘记用“master”填写“Branches to build”文本字段)
See also attachment screenshot image:
另见附件截图:
回答by Mike Rylander
You can use :^(?!.*master).*$
as the branch specifier in Jenkins and all branches except master will be built. See answer: https://stackoverflow.com/a/18709097/444639
您可以:^(?!.*master).*$
在 Jenkins 中用作分支说明符,并且将构建除 master 之外的所有分支。见答案:https: //stackoverflow.com/a/18709097/444639
回答by hi.nitish
You can use Repository, filter by name(wildcard). Here just provide :^(?!.master).$.
您可以使用存储库,按名称过滤(通配符)。这里只提供:^(?!. master)。$.
or you can use filter branch using wildcard and exclude master there:as it successfully scans but later removes from organisation folder scan in case you are using github or bitbucket team project.
或者您可以使用通配符使用过滤器分支并在那里排除 master:因为它成功扫描但稍后从组织文件夹扫描中删除,以防您使用 github 或 bitbucket 团队项目。
回答by sashoalm
@Mike's answer would work for most, but note that :^(?!.*master).*$
would match anything that doesn't contain master, i.e. a branch called feature/add-remaster-functionality
won't be built as well. A better way would be :^(?!.*^master$).*$
which matches only master, or even :^(?!.*^(master|origin/master)$).*$
which would match master or origin/master.
@Mike 的答案适用于大多数情况,但请注意,它:^(?!.*master).*$
会匹配任何不包含 master 的内容,即feature/add-remaster-functionality
也不会构建名为的分支。更好的方法是:^(?!.*^master$).*$
哪个只匹配 master,甚至:^(?!.*^(master|origin/master)$).*$
哪个匹配 master 或 origin/master。