Hudson/Jenkins Git 构建所有分支

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

Hudson/Jenkins Git build all branches

gitjenkinshudson

提问by babsher

We have a lot of developers creating feature branches that I would like to build. Nightly we run a code quality tool that needs to run on every branch. I also would not like a static configuration because the number of branches changes every few weeks.

我们有很多开发人员创建了我想要构建的功能分支。每晚我们运行一个代码质量工具,需要在每个分支上运行。我也不喜欢静态配置,因为分支的数量每隔几周就会发生变化。

回答by Tomasz Bartczak

In Git configuration there is a field 'Branch Specifier (blank for default): ' if you put there ** it will build all branches from all remotes.

在 Git 配置中有一个字段 'Branch Specifier (blanch Specifier (blank for default): ' 如果你把它放在那里 ** 它将从所有远程构建所有分支。

having that you can use an environment variable ${GIT_BRANCH} e.g. to set a title for the build using https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Pluginor for other purposes

有了它,您可以使用环境变量 ${GIT_BRANCH} 例如使用https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin或其他目的设置构建的标题

回答by Squrppi

I had the same problem to be solved. Specifically, make a zip file of all branches and offer those as artifacts to be used in different test jobs.

我有同样的问题需要解决。具体来说,制作所有分支的 zip 文件,并将它们作为工件提供,以用于不同的测试作业。

In "Branches to build", put "**"

在“要构建的分支”中,输入“**”

Then, Execute shell:

然后,执行shell:

while read -ra ITEM; do
  for i in "${ITEM[@]}"; do
    git checkout $i
    <do your stuff>
  done
done <<< $(git branch -r | grep -v "HEAD ->" | xargs -L 1 | cut -d'/' -f2)

This reads the list of branches, checkouts each of them separately and allows to do stuff in each of them. The <<< command converts this output:

这会读取分支列表,分别签出每个分支并允许在每个分支中执行操作。<<< 命令转换此输出:

  origin/HEAD -> origin/master
  origin/branch1
  origin/master
  origin/secondbranch

into checkout usable list:

进入结帐可用列表:

branch1
master
secondbranch

回答by kert

Old question but somewhat more fitting answer. The multi-branch plugin below allows you to create a build item type that fans out sub-projects with branches, syncing config automatically from top level to sub-projects

老问题,但更合适的答案。下面的多分支插件允许您创建一个构建项类型,用分支扇出子项目,自动从顶级同步配置到子项目

https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin

For a somewhat more involved approach, Seed plugin gives you a lot of flexibility defining sub-jobs

对于更复杂的方法,Seed 插件为您提供了很大的灵活性来定义子作业

https://github.com/jenkinsci/seed-plugin/wiki

https://github.com/jenkinsci/seed-plugin/wiki

回答by Delta Echo

The ** for branch specifier will run against all branches AND all tags. If you just want branches, use a branch specifier of refs/heads/*

** for 分支说明符将针对所有分支和所有标签运行。如果您只想要分支,请使用 refs/heads/* 的分支说明符