1
votes

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:[email protected]:data-layer/engineering-parser.git</connection>
        <developerConnection>scm:git:[email protected]: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!

2

2 Answers

0
votes

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

0
votes

[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 "[email protected]"
git config --global user.name "PAT"

enter image description here