Maven - Error Releasing Code to GitHub (Hangs After Push)

10,826

Solution 1

Considering the source of git builtin-push.c, that means that somehow, no remote are defined for the local Git repo used by the maven script.

    static int do_push(const char *repo, int flags)
    {
        int i, errs;
        struct remote *remote = remote_get(repo);

        const char **url;
        int url_nr;


        if (!remote) {
            if (repo)
                die("bad repository '%s'", repo);
            die("No destination configured to push to.");
        }

As illustrated by this blog post, the maven config is not the all story.

~/foo/mikeci-archetype-springmvc-webapp$ git remote add origin [email protected]:amleggett/mikeci-archetype-springmvc-webapp.git

A remote add is still required, before specifying the maven scm parameters:

Updating the POM

For Maven to function effectively, you should always ensure that you include project VCS information in your POM file.
Now that we’ve added the archetype to a Git repository we can include the appropriate <scm> configuration:

  <scm>
   <connection>
   scm:git:ssh://github.com/amleggett/${artifactId}.git
   </connection>
   <developerConnection>
   scm:git:ssh://[email protected]/amleggett/${artifactId}.git
   </developerConnection>
   <url>
   http://github.com/amleggett/${artifactId}
   </url>
  </scm>

The same blog post adds:

It’s important to understand the meaning of each of the child elements of <scm>.

  • The <connection> element defines a read-only url and
  • the <developerConnection> element a read+write url.

For both of these elements the url must adhere to the following convention:

 scm:<scm implementation>:<scm implementation-specific path>
  • Finally, the <url> element content should point to a browsable location and for me this is the GitHub repository home page. Note that in all cases, I’m using an interpolated value which is my project artifactId.

One handy tip is that you can verify this configuration by using the maven-scm-plugin.
This plugin offers ‘vendor’ independent access to common VCS commands by offering a set of command mappings for the configured VCS. The validate goal should confirm all is well:

~/foo/mikeci-archetype-springmvc-webapp$ mvn scm:validate
[INFO] Preparing scm:validate
[INFO] No goals needed for project - skipping
[INFO] [scm:validate {execution: default-cli}]
[INFO] connectionUrl scm connection string is valid.
[INFO] project.scm.connection scm connection string is valid.
[INFO] project.scm.developerConnection scm connection string is valid.
[INFO] --------------------------------------------------------------
[INFO] BUILD SUCCESSFUL

Solution 2

I have run into the same problem and I traced this to the fact that git is requiring a passphrase, but Maven has no way to specify an appropriate passphrase, so the process essentially hangs. Note that this problem is limited to Windows.

The solution is to run ssh-agent. This can be found in C:\Program Files (x86)\Git\bin\. After you run it, it outputs some environment variables that you need to set. For example:

SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2792; export SSH_AGENT_PID;
echo Agent pid 2792;

So, you need to place these in your environment:

C:\> set SSH_AUTH_SOCK=/tmp/ssh-LhiYjP7924/agent.7924
C:\> set SSH_AGENT_PID=2792

Then, you will need to add a passphrase for your particular key file. Generally, if you issued a command like git fetch origin master for your project, you will get a passphrase prompt like: Enter passphrase for key '/c/Users/Anthony Whitford/.ssh/id_rsa' -- that is the file that you need to register with the agent. So, the command is:

C:\> ssh-add "/c/Users/Anthony Whitford/.ssh/id_rsa"

It will prompt you for a passphrase, so enter it. You should see an Identity added message. Now, the agent knows the passphrase so that you will not be prompted to specify it anymore.

If you have multiple instances of command prompts, make sure that each command prompt has the appropriate SSH_AUTH_SOCK and SSH_AGENT_PID environment variables set. You can validate that this is working by running a command like ssh -v [email protected] and if you DO NOT get prompted for a passphrase, it is working!

Note that when you logoff, the ssh-agent will shut down and so when you log back in or restart your computer, you will need to repeat these steps. My understanding is that your passphrase is stored in memory, not persisted to disk, for security reasons.

Solution 3

The mvn release:prepare goal always runs in non-interactive mode, so you can't enter the ssh passphrase git is waiting for while pushing to the remote repository. You can use an SSH agent to manage that, but if this problem only appears during the release process, there is another solution : preparing the release locally, and pushing the tag afterwards.

For this you have to use version 2.1+ of maven-release-plugin that comes with the pushChanges parameter.

mvn -DpushChanges=false release:prepare 

By the way, your tag is created into your local GIT repository and you can then push it to the remote repository as usual, with a git push command.

This method is useful for Eclipse users because Eclipse comes with an embedded ssh-agent but this agent is not used by maven while performing a release:prepare, even when using eGit.

Solution 4

These are the exact sequence of commands I followed to get rid of this error

C:\Program Files (x86)\Git\bin>bash

bash-3.1$ eval 'ssh-agent -s'
SSH_AUTH_SOCK=/tmp/ssh-ZARFN11804/agent.11804; export SSH_AUTH_SOCK;
SSH_AGENT_PID=10284; export SSH_AGENT_PID;
echo Agent pid 10284;

bash-3.1$ exec ssh-agent bash
bash-3.1$ ssh-add "/c/Users/idntus/.ssh/id_rsa"
Enter passphrase for /c/Users/idntus/.ssh/id_rsa:
Identity added: /c/Users/idntus/.ssh/id_rsa (/c/Users/idntus/.ssh/id_rsa)

bash-3.1$ mvn release:prepare release:perform

Solution 5

The only thing which worked for me was specifying GIT user name and password as maven parameters:

mvn -Dusername=jenkins -Dpassword=******** release:prepare release:perform

To hide password in Jenkins output console I installed and configured Mask Passwords Plugin.

Share:
10,826
Taylor Leese
Author by

Taylor Leese

I herd cats and make services scale -- sometimes at the same time.

Updated on June 06, 2022

Comments

  • Taylor Leese
    Taylor Leese about 2 years

    I'm attempting to run the mvn release:prepare goal and it's hanging after the push. Any idea what I could be doing wrong?

    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] BUILD SUCCESSFUL
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] Total time: 8 seconds
    [INFO] [INFO] Finished at: Tue Jul 13 23:54:59 PDT 2010
    [INFO] [INFO] Final Memory: 55M/294M
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] Checking in modified POMs...
    [INFO] Executing: cmd.exe /X /C "git add -- pom.xml"
    [INFO] Working directory: C:\development\taylor\my-app
    [INFO] Executing: cmd.exe /X /C "git status"
    [INFO] Working directory: C:\development\taylor\my-app
    [INFO] Executing: cmd.exe /X /C "git commit --verbose -F C:\Users\TAYLOR~1\AppData\Local\Temp\maven-scm-1932347225.commit pom.xml"
    [INFO] Working directory: C:\development\taylor\my-app
    [INFO] Executing: cmd.exe /X /C "git symbolic-ref HEAD"
    [INFO] Working directory: C:\development\taylor\my-app
    [INFO] Executing: cmd.exe /X /C "git push [email protected]:tleese22/my-app.git master:master"
    [INFO] Working directory: C:\development\taylor\my-app
    >>>> hangs here <<<<
    

    Below is the SCM section of my pom.xml:

    <scm>
        <connection>scm:git:git://github.com/tleese22/my-app.git</connection>
        <developerConnection>scm:git:[email protected]:tleese22/my-app.git</developerConnection>
        <url>http://github.com/tleese22/my-app</url>
    </scm>
    
    ...
    
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.0</version>
    </plugin>
    

    Below is my .git/config:

    [core]
        repositoryformatversion = 0
        filemode = true
        logallrefupdates = true
        bare = false
    [branch "master"]
        remote = origin
        merge = refs/heads/master
    [remote "origin"]
        url = [email protected]:tleese22/my-app.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        pushurl = [email protected]:tleese22/my-app.git
    

    Here's the result of git show origin:

    $ git remote show origin
    Enter passphrase for key '/c/Users/Taylor Leese/.ssh/id_rsa':
    * remote origin
      Fetch URL: [email protected]:tleese22/my-app.git
      Push  URL: [email protected]:tleese22/my-app.git
      HEAD branch: master
      Remote branches:
        gh-pages new (next fetch will store in remotes/origin)
        master   new (next fetch will store in remotes/origin)
      Local branch configured for 'git pull':
        master merges with remote master
      Local ref configured for 'git push':
        master pushes to master (up to date)
    
    $ git status
    # On branch master
    nothing to commit (working directory clean)
    
  • Taylor Leese
    Taylor Leese almost 14 years
    I think my issues is related more to a possible issue with the maven-release-plugin and git rather than me configuring the <scm> section incorrectly, but not positive.
  • VonC
    VonC almost 14 years
    @Taylor: I agree. The important point in my answer is the 'git remote add'. The <scm> section of the answer is more here for adding some general informations to the topic.
  • kospiotr
    kospiotr over 10 years
    This is actually the best possible answer that also includes workaround for ss-agent issues. You saved me a lot of time. Thanks a lot.
  • Grim
    Grim about 10 years
    Can i use pageant instead? Or is pageant for putty only?
  • AWhitford
    AWhitford over 9 years
    Pageant should work too as it supports SSH. the.earth.li/~sgtatham/putty/0.63/htmldoc/Chapter9.html#page‌​ant
  • Brovoker
    Brovoker over 9 years
    What if there are more projects running on the CI server?
  • VonC
    VonC over 9 years
    @Brovoker it would be best to ask that question as a new one (this one is 5 years old, and I don't have enough information to answer your comment)
  • Nick Radov
    Nick Radov over 8 years
    It may be easier to add <pushChanges>false</pushChanges> in the pom.xml file.