git 我如何配置 Jenkins 以构建所有分支,但我排除的少数分支除外?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30095583/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:59:19  来源:igfitidea点击:

How do I configure Jenkins to build all branches except a few which I exclude?

regexgitjenkins

提问by TafT

We have some code in git and I started setting up Jenkins to grab our branches and try a compile. It seems that a few of the branches may have begun to rot in the years since they were last built, as they fail to finish a make.

我们在 git 中有一些代码,我开始设置 Jenkins 来获取我们的分支并尝试编译。似乎有一些树枝在上次建造后的几年里可能已经开始腐烂,因为它们没有完成一次制作。

I would like to build all branches that are found, except for a list of excluded ones. Is this possible in Jenkins? This will let me get things up and running, then come back to enable more branches as I try to fix them.

我想构建所有找到的分支,除了排除的分支列表。这在詹金斯有可能吗?这将使我能够启动并运行,然后在我尝试修复它们时回来启用更多分支。

What I have tried so far

到目前为止我尝试过的

Regex with lookahead

正则表达式与前瞻

Looking at the 'Git > Branches to build' option I was hopeful that I could replace the default '**' wildcard with a :. A bit of digging about and double checking with http://rubular.com/suggested that the following might do what I wanted.

查看“Git > Branches to build”选项,我希望我可以用 : 替换默认的“**”通配符。对http://rubular.com/进行一些挖掘和仔细检查表明以下内容可能符合我的要求。

:^(?!origin/exclude\-this\-branch\.v1|origin/exclude\-this\-branch\-too.v2)(\S+)

:^(?!origin/exclude\-this\-branch\.v1|origin/exclude\-this\-branch\-too.v2)(\S+)

Now there is an assumption here about the regex engine running in the background. I would hope it might understand lookahead, but if it does not that explains why this method fails. It seems to build all the branches, including the one I am try to exclude. Maybe I just need to find some more debug?

现在这里有一个关于在后台运行的正则表达式引擎的假设。我希望它可以理解前瞻,但如果它不能解释为什么这种方法会失败。它似乎建立了所有分支,包括我试图排除的分支。也许我只需要找到更多的调试?

Looked for similar questions here

在这里寻找类似的问题

I came across Jenkins/Hudson Build All Branches With Prioritizationwhich seemed to contain a possible solution in that some added an inverseoption to branch matching https://github.com/jenkinsci/git-plugin/pull/45sounds like what I need. Sadly this does not seem to be in the version of Jenkins I have, which is odd as 2011 is a long time ago.

我遇到了Jenkins/Hudson Build All Branches With Prioritization它似乎包含一个可能的解决方案,因为有些人添加了一个反向选项来匹配分支https://github.com/jenkinsci/git-plugin/pull/45听起来像我需要的. 可悲的是,这似乎不在我拥有的 Jenkins 版本中,这很奇怪,因为 2011 年是很久以前的事了。

The System I Am Using

我正在使用的系统

Ubuntu LTS 14.04. Jenkins ver. 1.611. GNU tool chains to make C/C++ code.

Ubuntu LTS 14.04。詹金斯版。1.611。用于制作 C/C++ 代码的 GNU 工具链。

采纳答案by Jesper R?nn-Jensen

How about using

怎么用

^(?!.*master).*$

as branch specifier. This regexp means all branches not matching master.

作为分支说明符。这个正则表达式意味着所有分支都不匹配 master。

Breakdown:

分解:

^(?!.*master).*$
^                ---> beginning of string
 (?!        )    ---> negative lookahead find all that doesnt match
    .*           ---> zero or more of 'any' character
      master     ---> should not match master
             .*$ ---> will match anything to the end of string

Related: https://stackoverflow.com/a/18709097/109305

相关:https: //stackoverflow.com/a/18709097/109305

回答by Luke Cottage

I needed using the Jenkins tool "filter branch by regex", and I discovered flavor of that regex works just with back reference. So, following the Jesperresponse and this issue, here I did two more examples:

我需要使用 Jenkins 工具“按正则表达式过滤分支”,我发现该正则表达式的风格仅适用于反向引用。所以,按照Jesper 的回应和这个问题,我在这里又做了两个例子:

^(?:.*release\/\d+.\d+.\d+(?!.))$
// check all branches like "release/0.0.0" or "origin/release/1.2.3"
^(?:.*release\/\d+.\d+.\d+_any)$
// check all branches like "release/0.0.0_any" or "origin/release/1.2.3_any"

I hope this would helpful for someone

我希望这对某人有帮助

EDIT - New example

编辑 -新示例

^(?:origin\/develop|origin\/master|origin\/release\/\d+\.\d+\.\d+(?!.)|origin\/release\/\d+\.\d+\.\d+(?:_uat|_preprod))$

or

或者

^(?:.*develop|.*master|.*release/\d+\.\d+\.\d+(?!.))$