This question involves Git plugin, Stash, and SonarQube integration, so 
there are multiple bits that we need to coordinate.


   1. We are using Stash with the Jenkins Web Hook to trigger builds when 
   developers push code to a branch.
   2. The build checks the code out to a local branch using the remote 
   branch name.
   3. The build runs sonar analysis and sets the sonar.branch property to 
   the local branch name.
   4. The team creates a pull request for the branch.
   5. When the pull request is merged, the branch in Stash is deleted, and 
   the SonarQube project for the branch is deleted.

In some cases, what we see is a bit different.  By the time the jenkins job 
is executed for a commit, the pull request has already been created.  In 
this case, when the Git plugin pulls the code and does the checkout on the 
commit, there are two branches, the one the developer pushed, and the one 
Stash created for the PR.  Git plugin is setting the GIT_BRANCH property to 
origin/pull-requests/23/from  instead of origin/feature/branchname.

In this case, when the build runs, the sonar.branch ends up being set to 
feature-branchname and we end up with a SonarQube project named 
"groupId:artifactid:pull-requests-23-from"  instead of 
"groupId:artifactId:feature-branchname".  

Now, when the team merges the pull request in Stash, the options to delete 
the branch and cleanup the SonarQube project are selected.  The Stash 
branch "feature/branchname" is deleted, but the SonarQube project is not 
deleted because the SonarQube project name (...:pull-requests-23-from) does 
not match the Stash branch name being deleted.

The problem seems to be caused by the fact that the commit has two branches 
associated with it.  From our perspective, the easiest solution is to force 
Git to use the branch name that was pushed by the developer, and to ignore 
pull-request type branches.
"Checking out Revision c3db27a8df3b68e927af8c5e01791bc270e7a90b 
(origin/pull-requests/6737/from, 
origin/DE00000-TA00000-switchCaseLines+addPrivateConstructor)"

"GIT_BRANCH=origin/pull-requests/6737/from"


How can we prevent Git plugin from using the pull-requests branch name?

Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/cc7672c2-cf12-4e4b-b0b0-6469967ec870%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to