0

I am currently trying to publish some built assets as npm package, to be able to pull it onto different environments like staging or production.

My Pipeline

  • a docker agent (own image: alpine + git + ssh)
  • 3 stages
    • build (npm install/build, private registry)
    • test
    • publish
      • npm version (does change package.json and package-lock.json)
      • npm publish (package is saved in private registry)
      • git add ... git commit ... (I thought those are done by npm version but...no?!)
      • git push <= here is the problem

The error:

git push HEAD:refs/remotes/origin/master
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push HEAD:refs/remotes/origin/master HEAD:<name-of-remote-branch>

I already tried some different git push calls like:

git push -u ${env.GIT_BRANCH} HEAD:${env.GIT_BRANCH}
git push -u origin HEAD:${env.GIT_COMMIT}
git push HEAD:refs/remotes/${env.GIT_BRANCH}

With

GIT_BRANCH=origin/master
GIT_COMMIT=0e0037b8ec27345f83ff4e08f1cf6133d3889dda

git show-ref

0e0037b8ec27345f83ff4e08f1cf6133d3889dda refs/remotes/origin/master

Update:

After changing into a branch with git checkout -b temp_${env.BUILD_NUMBER} and git push --repo ${GIT_URL} --set-upstream ${GIT_URL} ${env.GIT_BRANCH} the error changes to

 ! [remote rejected] origin/master -> origin/master (deny updating a hidden ref)
error: failed to push some refs to 'git@...myrepo.git'
andymel
  • 4,538
  • 2
  • 23
  • 35
  • I don't know anything about Jenkins or npm, but it seems to me that Git is saying quite clearly that you're in detached head mode. – matt Dec 07 '20 at 19:50
  • That's why I added `HEAD:refs/remotes/origin/master` but it just writes the same error and concatenates HEAD: again...but isn't that the HEAD part I already added with the master branch? – andymel Dec 07 '20 at 21:04
  • Some discussion here, don't know if it's relevant: https://stackoverflow.com/questions/34265266/remote-rejected-errors-after-mirroring-a-git-repository – matt Dec 07 '20 at 21:55
  • The checkout happens via the jenkins git plugin (poll git every minute and build on commits). But I push via the git of the docker build agent. I guess the problems arise because of that but I found no other way to push the version change back into the repo via the jenkins plugin – andymel Dec 07 '20 at 22:07

0 Answers0