On Sun, Jan 27, 2019 at 2:14 PM Faad Sayaou <faad...@gmail.com> wrote:

> 0
>
> I have a stage at the end of my pipeline job which has to push changes
> back to a particular Gitlab branch. After trying out several solutions
> proposed on stackoverflow, I am still not able to push to the branch
>
> sh("git add .")
> sh("git commit -a -m ' New changes'")
> sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@<REPO> ')
>
> I expected it to be pushed to the branch which it checked out from but I
> get the following result on the console
>
>    - git commit -a -m ' New changes' [detached HEAD bc78567] New changes
>    - Everything up-to-date
>
> any reason for this issue?
>

The git plugin default behavior is to checkout without creating a branch.
That is why the output of `git commit` includes `detached HEAD ...`.

That made it easier to switch between different commits on different
branches from inside a single workspace.  That was a common use model with
Freestyle jobs.  It is not a common use model with Pipeline jobs.

Because there is no branch defined in the workspace, git cannot infer the
destination branch to which the changes should be pushed.  You can pass an
additional argument to `git push` which tells it to push the HEAD revision
to the specific named branch you want.  For example, if the remote
destination branch is named 'master', the command would be:

git push https://${GIT_USERNAME}:${GIT_PASSWORD}@<REPO> HEAD:master

 Mark Waite

> --
> 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 jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/00dbb024-1cb8-47f5-bdb5-255c3e2f0907%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/00dbb024-1cb8-47f5-bdb5-255c3e2f0907%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Thanks!
Mark Waite

-- 
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 jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAO49JtEdM%2BHSPzOay5WVztNiUK5Yxpnj1_dipM7ypCxAnEmfaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to