Currently using VSTS to build Spring Boot applications with Maven. Trying to figure out how to use/get the Maven Version within the build and release process.
Is it possible?
Advertisement
Answer
Here is a script that will get the version of maven (given the path) and store the version number in a variable that other tasks can use later in the build.
$mvn = "$Env:M2_HOMEbinmvn.bat" $version = (& $mvn -v | select-string -pattern '(ApachesMavens)([^s]*)').Matches.Groups[2].Value Write-Output ("##vso[task.setvariable variable=MavenVersion;]$version")
The name of the environment variable is MavenVersion as you can see in the last line. You can use this variable like you would any other environment variable in subsequent scripts or build processes.
I tested this script on the Hosted Build machine, so the path to Maven was under M2_HOME and ended with .bat (Maven 2). You may want to add more code to figure out the path to Maven more generically.