开发者

git jenkins advanced feature

开发者 https://www.devze.com 2023-03-22 09:38 出处:网络
Our team uses jenkins and git.We are looking to implement the advanced feature of the git plugin that allows for pre-builds before pushing commits to the blessed repository.See https://wiki.jenkins-ci

Our team uses jenkins and git. We are looking to implement the advanced feature of the git plugin that allows for pre-builds before pushing commits to the blessed repository. See https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeatures

However, I am having trouble understanding the whole process.

Here's an excerpt:

开发者_开发百科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.

What I understand is,

  1. Developers create remote branches, from which jenkins will pull from
  2. jenkins will merge the branch with its integration branch and build
  3. If the build succeeds, the merge will be pushed to blessed-repo/master.

The question is, if the build fails, what is the state of the integration branch? I would only assume that it somehow reverts back to the commit before the merge. If not, then the integration branch would keep the merge that broke the build, making it impossible for other branches to be merged in and built.

Is this true? Unfortunately, its not clear from the wiki.

Also, does anyone know of an example I can look at?


From what I can see of the GitSCM.checkout method, the merge begins first by a checkout, and, if the merge fails, restore the candidate branch with another 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");
}

So I don't think a failed merge has any consequence on subsequent builds.

0

精彩评论

暂无评论...
验证码 换一张
取 消