I am new to Git and also to Jenkins. My problem is that I can\'t get the Jenkins Maven release plugin to work.
When I build a common Maven build with Jenkins, it wor
None of the other answer's Jenkins configurations worked for me without having to create manual steps. What indeed works is plain simple:
Repository URL: <repo>
Branches to build: master
Checkout/merge to local branch (optional): master
I had the same problem. I tried Constantine's solution, that worked perfectly but the tag and the commits were pushed on the "localbranchname" remote repository.
So I did the same but manually : first add a pre-steps shell script :
git branch -f localJenkins
git checkout localJenkins
Then a post-steps shell script :
git checkout master
git rebase localJenkins
git branch -D localJenkins
git push origin master
git push --tag
This works ! This way, you don't have jenkins remote branch, commits and tag will be on the master (or other) branch.
hope this helps !
In Git, when you have a branch checked out, like master or dev or any other local branch, your HEAD (file in .git folder) will contain a reference to the corresponding branch. Therefore it is "attached".
When you perform some operations like rebase, merges or when you're checking out a particular commit, i.e. anytime you see "no branch", your HEAD doesn't have a reference to any local branch but points directly to the commit, i.e. it has the actual SHA-1 inside. That means it is detached - detached from any branch. There is no new reference "no branch" created.
The command git symbolic-ref HEAD
checks if the HEAD content is a reference or a SHA-1 and prints it out.
You can see that by doing:
git checkout master
git symbolic-ref HEAD
git checkout HEAD~2 # going two commits back
git symbolic-ref HEAD
git checkout master # coming back
Now, most of the time the Git plugin in Jenkins works with the code in detached HEAD state. I'm not sure how the Maven release plugin works, but I'm 99% sure that it requires you to release from a specific branch. In order to fix that, I would recommend to specify something like the following as a prebuild step or shell command:
git checkout master; git pull origin master
That will solve the problem, I hope ;)
UPDATE (November 2015): Please, note that this solution was given for a specific version of Git plugin (1.1.26). In later versions, the plugin was updated to make configuration easier.
For Jenkins Git plugin version 1.1.26 try this:
Go to Job Configuration. Scroll down to Git section and click "Advanced..." button under "Repositories". Then set:
Name: origin
Refspec: +refs/heads/branch-0.1:refs/remotes/origin/localbranchname
Then click another "Advanced..." button and set:
Checkout/merge to local branch (optional): localbranchname
You can name the local branch as you like, but the destination in Refspec must match the local branch name in that optional field (in this case "localbranchname"). This will attach HEAD to localbranchname like this:
HEAD -> refs/heads/localbranchname -> 7a698457751bdc043cfda631b81e3812c5361790
Maven Release should pass now in Jenkins.
By the way, this works for me with Jenkins 1.492 and Jenkins Git plugin version 1.1.26.
(SOLVED)
Hi, I had the same issue when trying to do a parametrized release build from a branch with maven-release-plugin:2.5.3 and maven-scm-provider-jgit:1.9.5.
I wanted to be able to select the branch for the "parametrized release build" this did not work and when I chose "Checkout/merge to local branch (optional)" it worked but ended up with a branch "origin/origin/mybranch" in remote (repeated origin).
So:
Add "Git Parameter" to "This project is parameterized"
Name: branch
ParameterType: Branch
Click Advanced:
Branch Filter:origin/(.*)
(this was the trick!)
Git Repository:
Branches to build: refs/remotes/origin/${branch}
Additional Behaviors: -> Check out to specific local branch
Branch Name: ${branch}
Have fun :-)
Got same problem. @Eugene solution worked only once. There was error in second try - "can't delete HEAD from repository" or something like this.
I've founded this (source):
And m2 extra steps (pre-build)
git checkout master || git checkout -b master
git reset --hard origin/master
And now i think its ok.