I am trying to implement versioning strategy of our apps on pom.xml via CI/CD.
I have followed the solution to this question and applied powershell script task on Azure DevOps pipeline: How to update version in POM file on branch after build number is incremented in Azure Pipeline
I can now see the incremented pom version on the working directory but I am having difficulty in commit and push this changes back to azure repo.
Do I need to run the git commands as well? Do you have example in mind? Or do you have any alternative approach in this objective?
Thank you
Generally, in the source repository, it is recommended keeping the value of
<version>as a placeholder in thepom.xmlfile. Similar to other properties if you want to update their values every time when building a new package version.So, it is not necessary to commit the updated
pom.xmlfile back to the source repository.Since the values of properties in the
pom.xmlfile also support environment variables, so you also can set the placeholders like as below. The expression '${env.VAR_NAME}' is referencing the value of the specified environment variable. More details, see here.In the pipeline, you just need to ensure the actual new values have been mapped to environment variables with the same names (i.e.,
PACKAGE_VERSION) referenced by the placeholders.By default, the pipeline variables (except secret variables) will be automatically map as environment variables. So, you just need to use the values to define the pipeline variables with the same names.
When building the package in pipeline, it will automatically use the actual values of environment variables to replace the placeholders in the
pom.xmlfile.If you want to use the run (build) number to set the package version, we have the predefined variable for it. You do not need to define extra pipeline variable. And in the
pom.xmlfile, you just need to set it like as below.If you still want to push the updated
pom.xmlfile back to Azure Repos, yes, you need to run the related git commands to do this.