I have a TFS build definition that deals with a java spring backend application that is built with Maven. I have a build step called "Maven pom.xml" where I obviously can set some options of the pom.xml.
I need to change the "version" tag in the pom.xml using TFS whilst building, so that the "info" endpoint in actuator serves the correct version number including the TFS build number.
1) Is this possible using the TFS UI at all?
2) If yes, should I change "Options" textbox content or "MAVEN_OPTS" and how do I feed parameters there, that change in the pom.xml?
解决方案
Yes, it is possible. Follow these steps:
1) Create another maven build step before the maven build task with "package" goal.
2) Set "Goal(s)" to:
versions:set -DnewVersion=[VersionInformation] -DskipTests
[VersionInformation] can be any string denoting your desired version. You can use TFS variables here. An example for this string might be: 2.3.5.$(Build.BuildNumber)-RELEASE so your Goal for the versions:set maven build task would look like:
versions:set -DnewVersion=2.3.5.$(Build.BuildNumber)-RELEASE -DskipTests
Save your changes. This way, the build-info.properties file under /target/classes/META-INF folder will include your version number that will be served via the "info" actuator.
3) If you need to copy your build output to another place, make sure that you copy the META-INF folder as well. If your current copy step doesn't copy that folder to your ultimate drop place;
a. Create a "Copy files" build step after build step(s).
b. Write "$(build.sourcesdirectory)/target/classes/META-INF" into the "Source Folder" textbox.
c. Write * into the Contents textbox. That will copy all files in META-INF just in case.
d. Append "/classes/META-INF" to your normal drop place in the Target Folder textbox so that META-INF files are copied to the right place.
e. Save your changes.
This way, your build definition correctly sets the version information and copies the necessary files to your drop location. To access your version info, use your "info" actuator endpoint.