Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git jenkins advanced feature

Tags:

git

jenkins

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?

like image 402
Ken Hirakawa Avatar asked Jul 24 '11 20:07

Ken Hirakawa


People also ask

How Jenkins works with Git?

How does Jenkins integrate with Git? Go to Jenkins dashboard, click on “Manage Jenkins.” Now follow these steps- Manage Plugins -> 'Available' tab -> Enter Git in search bar and filter -> Install required plugin. After the installation, all you need to do is click on “Configure System” and go to the 'GitHub' section.

Can we connect Git with Jenkins?

Build integration With the help of the Git plugin Jenkins can easily pull source code from any Git repository that the Jenkins build node can access. The GitHub plugin extends upon that integration further by providing improved bi-directional integration with GitHub.

Is it possible to clone a Git repository in Jenkins?

There are two ways to clone the project(repository) from Github. Create a new Jenkins job called 'Clone-with-https', move to the “Source Control Management” setting, and choose “Git” options if you cannot see the Git options that mean the 'GitHub' plugin wasn't installed in the Jenkins machine.

How do I download Git Jenkins plugin?

Install the Git Plugin in JenkinsGo to “Manage Jenkins>>Manage Plugins”, open the “Available” tab and search for “Git plugin”, click on install button wait until the installation is done.


1 Answers

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.

like image 63
VonC Avatar answered Sep 21 '22 07:09

VonC