31

We are using Jenkins and just switched from a file based git repo without authentication to using GitBlit with proper authentication over http.

The problem is - how is maven supposed to authenticate itself in batch mode?

Updating each job with -Dusername and -Dpassword (and thus storing the password in the jobs) doesn't seem very feasible. I've read that settings.xml is supposed to work with git by specifying the git server as the id, but whatever I do it has no effect (i.e the release plugin prompts for credentials).

pom.xml:

<properties>
   <project.scm.id>git</project.scm.id>
</properties>
<scm>
   <connection>scm:git:http://myserver:8081/r/gitauthtest.git</connection>
   <developerConnection>scm:git:http://myserver:8081/r/gitauthtest.git</developerConnection>
</scm>

settings.xml contents

<settings>  
   <servers>  
      <server>
         <id>git</id>  
         <username>myUser</username>  
         <password>myPassword</password>  
      </server>   
   </servers>
</settings>

Is there any way to get this working? I cannot believe that a task as simple and extremely common as this doesn't have an easy standard solution.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Rasmus Franke
  • 4,434
  • 8
  • 45
  • 62

1 Answers1

50

Based on the docs you have to use a special property, project.scm.id, to define the id of the appropriate server entry in your settings.xml file.

<properties>
  <project.scm.id>my-scm-server</project.scm.id>
</properties>

And the following in your settings.xml file:

<settings>  
   <servers>  
      <server>
         <id>my-scm-server</id>  
         <username>myUser</username>  
         <password>myPassword</password>  
      </server>   
   </servers>
</settings>

BTW: Check if you are using the most recent version of maven-release-plugin. The project.scm.id enhancement was introduced in version 2.3 as part of ticket MRELEASE-420. For example if you are using Maven 3.0.5 then you are by default only using version 2.0 of the maven-release-plugin. Much too old. Fix by adding something like below to your POM:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>                
            </plugin>
        </plugins>
    </pluginManagement>
</build>
schnatterer
  • 7,525
  • 7
  • 61
  • 80
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Tried this aswell without any effect, forgot to mention this in the question. We have no version specified, I assume maven picks the latest version in that case? – Rasmus Franke Feb 05 '15 at 08:21
  • Seems like we ran an old version of the release plugin and it seems to work with the latest. Thanks! – Rasmus Franke Feb 05 '15 at 09:16
  • 1
    Always define the plugin version by explicit usage of a pluginManagement otherwise you can't reproduce your results. – khmarbaise Feb 05 '15 at 11:26
  • 1
    Maven does *not* automatically use the latest version of the plugins since this would change your build every time any of your plugins releases a new version. – Geert Schuring Aug 25 '16 at 11:50
  • Works like a charm ... thean you :-) – Mahieddine M. Ichir Sep 27 '17 at 12:34
  • 1
    Is this still current? My `` section does not no any tag ``. – Herr Derb May 01 '18 at 07:55
  • The `..` section does not has any `...`tag...See https://maven.apache.org/pom.html#SCM – khmarbaise May 01 '18 at 10:04
  • It's not working for me, during the workflow it ask me ssh user password root: jenkins@192.168.10.10 see https://stackoverflow.com/questions/56846800/mvn-releaseprepare-and-perform-in-batch-without-password-typing – michele Jul 02 '19 at 13:34
  • Hi All, I just wanted to put the password, so what will be the password and how to get this from bitbucket account. Your help will be appreciated – KuldeeP ChoudharY Jul 21 '23 at 05:56