简体   繁体   English

Hudson/Jenkins Git 构建所有分支

[英]Hudson/Jenkins Git build all branches

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.我也不喜欢静态配置,因为分支的数量每隔几周就会发生变化。

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} eg to set a title for the build using https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin or for other purposes有了这个,您可以使用环境变量 ${GIT_BRANCH} 例如使用https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin或其他目的设置构建的标题

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

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

UPDATE 2021 This plugin is marked DEPRECATED 2021 年更新此插件已标记为已弃用

This plugin is deprecated.此插件已弃用。 Please move to the Multibranch Pipeline job type.请移至Multibranch Pipeline 作业类型。

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

The ** for branch specifier will run against all branches AND all tags. ** for 分支说明符将针对所有分支和所有标签运行。 If you just want branches, use a branch specifier of refs/heads/*如果您只想要分支,请使用 refs/heads/* 的分支说明符

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM