rabejens
rabejens

Reputation: 8162

Maven and Gitlab: release:prepare uses the wrong SCM URL

I am trying to do mvn release:prepare on a multi-module project which is hosted on a Gitlab server.

The pom.xml for my master POM contains:

<scm>
    <connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git</connection>
    <url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>

When I do mvn release:prepare -DautoVersionSubmodules=true, it compiles everything and runs the test, but then fails with:

[INFO] Executing: /bin/sh -c cd /home/somebody/git/my-project && git tag -F /tmp/maven-scm-1594218362.commit my-project-1.0.0
[INFO] Working directory: /home/somebody/git/my-project
[INFO] Executing: /bin/sh -c cd /home/somebody/git/my-project && git push http://my-git-server.example.com/git/somebody my-project-1.0.0
[INFO] Working directory: /home/somebody/git/my-project
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project iwes-lib-master: Unable to tag SCM
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] fatal: repository 'http://my-git-server.example.com/git/somebody/' not found
[ERROR] -> [Help 1]

So it is telling me the maven-release-plugin thinks that the parent directory to my Git repository is the repository, bailing out there.

Adding a developerConnection does not help.

When trying to use SVN, it fails with "Access Denied:

<scm>
    <connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git</connection>
    <developerConnection>ssh://[email protected]:10022/somebody/my-project.git</developerConnection>
    <url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>

gives me:

[INFO] Executing: /bin/sh -c cd /home/jra/Documents/git/my-project && git push ssh://[email protected]:10022/somebody my-project-master-1.0.0
....
[ERROR] Access denied.

So, it, again, uses the parent directory.

How do I force the release plugin to use the real URL I state there?

Upvotes: 8

Views: 18312

Answers (6)

LIU YUE
LIU YUE

Reputation: 2007

here is the solution that both release:prepare and release:perform are working nicely:

pom.xml:

<scm>
        <connection>scm:git:origin</connection>
        <developerConnection>scm:git:origin</developerConnection>
        <url>http://git-url/testci</url>
        <tag>HEAD</tag>
    </scm>
  1. mvn release prepare

    git remote set-url origin http://YOUR-USERNAME:YOUR-PASSWORD@$CI_SERVER_HOST/testci.git

    mvn clean -DskipTests -Darguments=-DskipTests release:prepare -e -DreleaseVersion=$ReleaseVersion -DdevelopmentVersion=$NextVersion-SNAPSHOT -Dtag="$TD-$ReleaseVersion" -DscmDevelopmentCommitComment="prepare for next development iteration $NextVersion-SNAPSHOT" -X -B

  2. mvn release perform

    mvn release:perform -DconnectionUrl='scm:git:http://git-url/testci.git' -Dusername="YOUR-USERNAME" -Dpassword="YOUR-PASSWORD" -e -Darguments="-Dmaven.javadoc.skip=true -Dmaven.test.skip=true" -s ci_settings.xml -B

Upvotes: 1

PGP
PGP

Reputation: 385

On windows 10 if using gitlab, the scm section might look like (for example):

   <scm>
     <url>https://gitlab.yourdomain.com/yourproject</url>
     <connection>scm:git:https://gitlab.yourdomain.com/yourproject.git</connection>
     <developerConnection>scm:git:https://gitlab.yourdomain.com/yourproject.git</developerConnection>
    <tag>HEAD</tag>
   </scm>

Supplying the user name and password in the mvn command line (below) gets around maven-on-Windows10 failures in running shell prompt-scripts or errors reading user-name:

    mvn release:clean release:prepare -Dusername=someUserName -Dpassword=somePassword

BUT: If you need to supply non-standard characters in your username and password (e.g. [email protected] and some#pwd! respectivley) then you will need to use URL-encoding on the command line as follows:

    mvn release:clean release:prepare -Dusername=fred%40somedomain.com -Dpassword=some%23pwd%21

Upvotes: 1

rabejens
rabejens

Reputation: 8162

EDIT: The workaround I proposed here does not work for release:perform, in fact, I did not find a feasible solution till today. I am now doing the release manually as I will describe below.

I investigated on this issue some more and I think it is a bug. I filed a JIRA for it: MRELEASE-900

I dumped maven-release-plugin and am now doing the release manually the following way (example: release 1.3.0, snapshot version is 1.3.0-SNAPSHOT):

  1. git checkout master && git pull just to be sure
  2. git checkout -b release-1.3 && git push -u origin release-1.3
  3. cd path/to/my/master/project
  4. mvn versions:set, it asks me to specify the new version for 1.3.0-SNAPSHOT, I enter 1.3.0
  5. git commit -a so the new version is checked-in
  6. git tag release-1.3.0
  7. git push && git push --tags - At this point, there is a tag release-1.3.0 in the branch release-1.3 where all relevant POM version numbers are 1.3.0
  8. git checkout master
  9. git merge release-1.3 - do not commit yet, I first update the versions.
  10. mvn versions:set, set new SNAPSHOT version, as per my convention, this would be 1.4.0-SNAPSHOT
  11. git commit -a
  12. git push

I can then create a Jenkins job or what I like on the tag release-1.3.0 to process the release.

-- Old answer for reference below --

After poking around and trying various things, I made some progress: I have to let the maven-release-plugin think that my-project.git is a directory and add a faux file to the URL.

The following works:

<scm>
    <connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</connection>
    <developerConnection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</developerConnection>
    <url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>

And the same with tSSH:

<scm>
    <connection>scm:git:http://my-git-server.example.com/git/somebody/my-project.git/.git</connection>
    <developerConnection>ssh://[email protected]:10022/somebody/my-project.git/.git</developerConnection>
    <url>http://my-git-server.example.com/git/somebody/my-project</url>
</scm>

Now release:prepare works, but release:perform fails because it wants to download from ssh://[email protected]:10022/somebody/my-project.git/.git.

Upvotes: 3

Romain
Romain

Reputation: 87

As some have said, those workaround can make work the prepare phase of the release but not the perform phase (in my case that was it). I finally managed to have a full release working by finding the correct way to enter the data to put the developperConnection tag :

<scm>
    <developerConnection>scm:git:[email protected]:groupProject/project.git</developerConnection>
    <tag>HEAD</tag>
</scm>

Many other URL format were accepted in my case but in the end failed during the perform or prepare phase of the release (scm:git:ssh://git@gitlab... for instance was having this problem). I don't know if this solution is specific to Gitlab or maybe my project but I spent a lot of time finding this workaround...

Upvotes: 5

OkieOth
OkieOth

Reputation: 3714

I ran in the same issue with a call like that

mvn deploy scm:tag

I'm using a gitlab installation and it also don't allow calls like this

[INFO] Executing: /bin/sh -c cd /home/user/prog/gitlab/test-user_server && git tag -F /tmp/maven-scm-482134407.commit test-user_server-1.1-SNAPSHOT
[INFO] Working directory: /home/user/prog/gitlab/test-user_server
[INFO] Executing: /bin/sh -c cd /home/user/prog/gitlab/test-user_server && git push [email protected]:testplus/test-user_server.git refs/tags/test-user_server-1.1-SNAPSHOT
[INFO] Working directory: /home/user/prog/gitlab/test-user_server
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] Permission denied, please try again.

The problem is this call

/bin/sh -c cd /home/user/prog/gitlab/test-user_server && git push [email protected]:testplus/test-user_server.git refs/tags/test-user_server-1.1-SNAPSHOT

But this call is not really necessary, because I start the mvn in the root of my git repository. Instead a command line call like the one below works.

git push origin refs/tags/test-user_server-1.1-SNAPSHOT

So I modified my scm configuration inside my pom.xml to a string like the following and it works for me like a charm.

<scm>
    <developerConnection>scm:git:origin</developerConnection>
</scm>

I develop under a Linux OS and so I have not tested if it works also on Windows system.

Upvotes: 5

Pere BG
Pere BG

Reputation: 618

I have the same issue, in my case the plugin pushes to remote the pom updated with the correct version but when is trying to generate the tag it fails because it tries to push the tag to the parent directory.

Push to master the pom updated with the correct version

git push git@myGitLabURL:parent/project.git refs/heads/master:refs/heads/master 

but when it tries to push the tag

push git@myGitLabURL:parent refs/tags/v1.46 

Have someone solved it?

Upvotes: 0

Related Questions