4

I am trying to implement Jenkins maven release with git. I followed this guide but my release is failing with below error. It is complaining while pushing. I am using workspace cleanup plugin so every time it should take the fresh copy of project. I am not sure why am I getting this error.

I tried to add a pre step which will do the "git fetch" and "git pull origin master" but I am still getting the error. It seems it is creating the local repo somewhere else than jenkins workspace. Can someone point me to correct direction?

10:44:05 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.2:prepare (default-cli) on project test: Unable to commit files
10:44:05 [ERROR] Provider message:
10:44:05 [ERROR] The git-push command failed.
10:44:05 [ERROR] Command output:
10:44:05 [ERROR] To ssh://abc.example.com/test.git
10:44:05 [ERROR] ! [rejected]          master -> master (fetch first)
10:44:05 [ERROR] error: failed to push some refs to 'ssh://gitlab@abc.example.com/test.git'
10:44:05 [ERROR] hint: Updates were rejected because the remote contains work that you do
10:44:05 [ERROR] hint: not have locally. This is usually caused by another repository pushing
10:44:05 [ERROR] hint: to the same ref. You may want to first integrate the remote changes
10:44:05 [ERROR] hint: (e.g., 'git pull ...') before pushing again.
10:44:05 [ERROR] hint: See the 'Note about fast-forwards' in 'git push --help' for details.
10:44:05 [ERROR] -> [Help 1]
user3847894
  • 986
  • 4
  • 16
  • 37
  • the problem is located here: `10:44:05 [ERROR] hint: Updates were rejected because the remote contains work that you do`... – khmarbaise Apr 28 '19 at 08:24
  • @khmarbaise, I know I will have to do a git pull but I don't know where. I am trying in the workspace directory but it is saying "Already Up To date". – user3847894 Apr 28 '19 at 11:08
  • I REALLY do not understand why I'm also having this issue. Nothing has ever happened on the remote since checkout (it is a few seconds ago the maven release plugin pulled the branch). It worked in the past for me for other projects, but I CANNOT use the maven release plugin in my current setup. – Merijn Vogel Feb 08 '21 at 10:51

2 Answers2

2

I fixed the issue by creating a new jenkins job. Everything was working fine after that.

user3847894
  • 986
  • 4
  • 16
  • 37
0

You should not have remote commits done on the repo branch your release:prepare is about to update. As mentioned here, this is a communication issue with other contributors to the same repo.

Make sure your local repo is up-do-date (git pull), then launch your mvn command.

This GitLab issue also suggested:

You could skip pushing back to master and just the commit with the new tag.

Run

mvn release:prepare release:perform -DpushChanges=false
git push —tags

Additional benefit: you do not spoil the master’s commit history with the two release-commits.
Of course now you need to bump your version somehow.
You could use the ci_pipeline_id approach via inclusion of this plugin.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I already tried git pull but no changes are there in the workspace directory. – user3847894 Apr 28 '19 at 06:26
  • @user3847894 Try the mvn -X ... command, in order to have more logs: you need to check if this is the master `branch` which is involved. – VonC Apr 28 '19 at 06:29
  • Yes I already tried mvn -X to get the debug logs and it is using master branch only. While specifying scm I used git with branch as "*/master" and option of "checkout local branch as master" – user3847894 Apr 28 '19 at 06:44
  • @user3847894 OK. Can you confirm your `master` HEAD commit (`git rev-parse master`: https://stackoverflow.com/a/9110527/6309) is the same commit as the one returned by `git ls-remote`? – VonC Apr 28 '19 at 06:56
  • @user3847894 Then the issue is not in your repo working tree (where everything is up-to-date), but in the Jenkins's one: try and select: "Delete workspace before build starts." in your Jenkins job, as in https://stackoverflow.com/a/28728663/6309 (no need to cleanup after the job, just before) – VonC Apr 28 '19 at 15:28
  • "Delete workspace before build starts." option is also enabled. Let me try from start – user3847894 Apr 29 '19 at 01:06