Reputation: 771
I am working with Jenkins, PowerShell, and Batch to create artifacts and maintain version control, but I am having issues with Git not doing as I expect it to. One job goes into the Upstream Job's workspace to get the git branch and AssemblyInfo.cs file. It then makes the necessary changes to the AssemblyVersion within the AssemblyInfo.cs file; however, when I go to commit, I don't get the expected results...
My code looks as follows:
CD "env:CurrentWorkspace" # variable containing ${WORKSPACE} value of upstream job
& git add .
& git status .
& git commit -m "some relavent update message"
& git push origin $env:CurrentBranch # This variable contains the branch name retrieved from the previous job
My output comes out as follows:
HEAD detached at 6737417
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: Project/Properties/AssemblyInfo.cs
[detached HEAD 02f2957] some relavent update message
Committer: jenkins <jenkins.full.name>
1 file changed, 1 insertion(+), 1 deletion(-)
Everything up-to-date
Sometimes 'Everything up-to-date' is a line that appears to have pushed to the expected branch.
The variable $env:CurrentBranch
is basically origin/branch-name
. I have also tried changes this to something slightly different like develop/branch-name
but end up getting a failure due to invalid branch name or something similar.
At this point, I am at a loss as I have tried a number of ways to get this to work, and most of my attempts just result in a message that appears to have been successful, yet not changes to the branches occur.
I have tried varying the command up doings things like:
git push origin ($env:CurrentBranch+":"+$env:CurrentBranch)
git push HEAD:$env:CurrentBranch
I am mostly looking for direction here, or perhaps someone to point out what I am doing wrong.
How do I push changes to a target branch when said branch was checked out in a different Job (I believe this is an example of a 'detached HEAD', however, I have not found anything that has alleviated my issue)?
Upvotes: 1
Views: 3012
Reputation: 1323183
It appears Jenkins would checkout a commit (a branch HEAD), instead of the branch itself. (see for instance JENKINS-6856)
In your script, try before the git add/commit
a git checkout $CurrentBranch
, making sure your new commit is done in a branch. Then it will be pushed.
Upvotes: 1