2

I am trying to implement azure devops on a scala project which is built in maven tool.

I have to use release management in the project so that i am using below scm connection and maven-release plugin as shown below in the pom.xml file.

...
...
<groupId>com.group.id</groupId>
    <artifactId>engineering-parsers</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
....
....
....
    <scm>
        <connection>scm:git:git@git.org.com:data-layer/engineering-parser.git</connection>
        <developerConnection>scm:git:git@git.org.com:data-layer/engineering-parser.git</developerConnection>
        <url>https://git.org.com/data-layer/engineering-parser</url>
        <tag>v1.0.0</tag>
    </scm>

...
...
<build>
     <plugins>
         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>3.0.0-M1</version>
                   <configuration>
                       <tagNameFormat>v@{project.version}</tagNameFormat>
                       <checkModificationExcludes>
                           <checkModificationExclude>pom.xml</checkModificationExclude>
                       </checkModificationExcludes>
                   </configuration>
               </plugin>
           </plugins>
</build>

...
...

I have added a maven task in the azure build pipeline as shown below and provided command release:prepare and tried with --batch-mode release:clean release:prepare -Dtag=2.0.0 -DreleaseVersion=2.0.0 -DdevelopmentVersion=2.0.1-SNAPSHOT -Dusername=Personal%20Access%20Token -Dpassword=xxxxxGIT PATxxxxx

enter image description here

While running the build pipeline, maven build is failing by throwing below error. enter image description here

It seems like that using the provided commands i am not able to connect to git repository and push the changes into repo.

Is there anything else I have to add while using maven release plugin with devops?

Any leads appreciated!

Antony
  • 970
  • 3
  • 20
  • 46

2 Answers2

1

[ERROR] The git-commit command failed. ....

It seems that you haven't pass the authentication information.

You could try to add the project.scm.id in your pom.xml file.

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

Then you could add a Settings.xml file to pass the auth.

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

Here is a doc, you could refer to it.

OR you could try to pass the authentication information in the command(Not recommended).

 release:prepare -Dusername=[username] -Dpassword=[password] 

You could refer to this ticket for more information.

According to the value in pom.xml rather than hard coding..Is there any way?

In order to achieve this goal, you need to use a powershell script to get the value of the corresponding position and set it as a pipeline variable.

For example:

$filePath = "filepath/pom.xml"
[xml]$pomXml = Get-Content $filePath
$version = $pomXml.project.version      
Write-Host "##vso[task.setvariable variable=version]$version"

In this case, you can get the parameter value corresponding to the location of the json file.

Then you could use the variables (e.g.$(version)) to replace hard coding.

Update:

You could try to add additional Command Line task before maven task to run the git config command.

git config --global user.email "you@example.com"
git config --global user.name "PAT"

enter image description here

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • I tried by passing the username and password, with and without **connectionUrl**. ```-B --batch-mode -Dtag=v1.0.0 release:prepare -DreleaseVersion=1.0.0 -DdevelopmentVersion=2.0.0-SNAPSHOT -DconnectionUrl=scm:svn:https://git.org.com/data-layer/engineering-parser -Dusername=antony -Dpassword=antony``` But still I am getting the same error. ```[ERROR] The git-commit command failed. [ERROR] Command output: [ERROR] *** Please tell me who you are. [ERROR] Run [ERROR] git config --global user.email "you@example.com" [ERROR] git config --global user.name "Your Name"``` – Antony Dec 15 '20 at 05:54
  • @Antony. From the scm git url connection and developerConnection, it seems that you are using the ssh key auth. Can you try to change to use the Https url? For example: `scm:git:https://git.org.com/data-layer/engineering-parser` – Kevin Lu-MSFT Dec 15 '20 at 07:32
  • Tried with providing the https connection parameter, but getting the same error – Antony Dec 15 '20 at 10:10
  • If I try the same https connection parameter in the IntelliJ IDE, the build is successful and release prepare is complete if i run below commands. ```--batch-mode release:clean release:prepare -Dtag=1.0.0 -DreleaseVersion=1.0.0 -DdevelopmentVersion=2.0.0-SNAPSHOT -Dusername=Personal%20Access%20Token -Dpassword=[PAT]``` – Antony Dec 15 '20 at 12:24
  • And the scm tags in pom.xml is as below. ``` scm:git:https://git.org.com/data-layer/engineering-parser.git 1.0.0 ``` – Antony Dec 15 '20 at 12:27
  • Tried the same command in the Azure build pipeline maven task, but ending up with the same error only. – Antony Dec 15 '20 at 12:28
  • Hi @Antony. Thanks for your information. In your local machine, the process could use the locally cached credentials, so it could work. In azure devops you could run git command to set the credentials before the maven task. Please check my update. Based on my test it could work. – Kevin Lu-MSFT Dec 16 '20 at 09:16
  • Thank you so much... Added a command line task which will perform below script and it works fine. ```git config --global user.email "mymail@org.com" git config --global user.name "PAT" git checkout -f devops-test``` – Antony Dec 16 '20 at 10:33
0

You need to add the parameter -B to the Maven call to avoid interactive mode.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • I have added ```--batch-mode -Dtag=v1.0.0 release:prepare -DreleaseVersion=1.0.0 -DdevelopmentVersion=2.0.0-SNAPSHOT``` and it is succeeded till git commit and failing with below error. ```[ERROR] The git-commit command failed. [ERROR] Command output: [ERROR] [ERROR] *** Please tell me who you are. [ERROR] [ERROR] Run [ERROR] [ERROR] git config --global user.email "you@example.com" [ERROR] git config --global user.name "Your Name" ``` – Antony Dec 11 '20 at 11:28
  • And also I need to give the ```-Dtag=v1.0.0 release:prepare -DreleaseVersion=1.0.0 -DdevelopmentVersion=2.0.0-SNAPSHOT``` According to the value in pom.xml rather than hard coding..Is there any way? – Antony Dec 11 '20 at 11:28
  • If you have further questions, please ask new questions on Stackoverflow. – J Fabian Meier Dec 11 '20 at 13:16