我们的团队使用 jenkins 和 git。我们正在寻求实现 git 插件的高级功能,该功能允许在将提交推送到 blessed 存储库之前进行预构建。参见 https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeatures
但是,我无法理解整个过程。
摘录如下:
Set up your Jenkins project, and leave the 'branch' field in the Git SCM blank. This will cause Jenkins to consider any change on any branch for building.
Next, pick a particular branch name as the integration target in the 'Advanced' section - (e.g. 'master', or 'stable'), and select 'Merge before build'.
Select 'Push GIT tags back to origin repository' from the post-build actions (this is required to update your centralised git repo with the results of the build).
Now, developers should never commit directly to your integration branch (the 'master' or 'stable'). Instead, they should either use feature branches, or create new remote branches on commit (e.g : "git push origin HEAD:refs/heads/myNewFeature"). You could also set up your GIT repository to only accept commits onto the integration branch from Jenkins.
You're done. Commits should now be automatically merged with the integration branch (they will fail if they do not merge cleanly), and built. If the build succeeds, the result of the merge will be pushed back to the remote git repository.
我的理解是,
- 开发人员创建远程分支,jenkins 将从中 pull
- jenkins 将分支与其集成分支 merge 并构建
- 如果构建成功, merge 将被推送到 blessed-repo/master。
问题是,如果构建失败,集成分支的状态是什么?我只假设它以某种方式恢复到 merge 前的提交。如果没有,那么集成分支将保留破坏构建的 merge ,使得其他分支无法 merge 和构建。
这是真的吗?不幸的是,它在 wiki 上并不清楚。
另外,有人知道我可以看的示例吗?
最佳答案
据我所见GitSCM.checkout
method , merge 首先从 checkout 开始,如果 merge 失败,则使用另一个 checkout 恢复候选分支:
// checkout origin/blah
ObjectId target = git.revParse(mergeOptions.getRemoteBranchName());
git.checkoutBranch(paramLocalBranch, target.name());
try {
git.merge(revToBuild.getSha1().name());
} catch (Exception ex) {
// We still need to tag something to prevent
// repetitive builds from happening - tag the
// candidate
// branch.
git.checkoutBranch(paramLocalBranch, revToBuild.getSha1().name());
[... tag applied ...]
buildData.saveBuild(new Build(revToBuild, buildNumber, Result.FAILURE));
throw new AbortException("Branch not suitable for integration as it does not merge cleanly");
}
所以我认为失败的 merge 不会对后续构建产生任何影响。
关于git jenkins 高级功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6809576/