1

When building code using azure pipeline I read version from pom file as follows:

[xml]$pomXml = Get-Content .\pom.xml
# version
Write-Host $pomXml.project.version
$version=$pomXml.project.version

And then I need to update snapshot version inside my pom. If the $version value is something like 1.44.4, how can I increase it to 1.44.5 inside shell script or any other way, because it seems like I cannot do operations on $version value.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
Channa
  • 3,267
  • 7
  • 41
  • 67
  • Do you want to increase the version in the pom.xml? (read it, increase and save?) – Shayki Abramczyk Jun 12 '19 at 09:34
  • My problem is how can I increase it inside pipeline? because something like `$version = $version +1` doesn't work – Channa Jun 12 '19 at 09:40
  • @Channa Refer to this answer: https://stackoverflow.com/questions/50330425/increment-variable-value-in-tfs-build-1 You can use this extension to update the variable value: https://marketplace.visualstudio.com/items?itemName=richardfennellBM.BM-VSTS-BuildUpdating-Tasks&ssr=false#qna – Mengdi Liang Jun 12 '19 at 10:20

2 Answers2

0

In your PowerShell script you can increase the number in this way:

# $version = 1.44.4
$splitted = $version.Split('.')
$splitted[2] = [int]$splitted[2] + 1
$newVersion = $splitted -join "."
# $newVersion = 1.44.5
# Now you can save the file with the new version:
$pomXml.Save("pom.xml")
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
0

You can also use the [Version] accellerator for this:

[xml]$pomXml = Get-Content .\pom.xml
$oldVersion = [version]$pomXml.project.version   # '1.44.4'
$newVersion = "{0}.{1}.{2}" -f $oldVersion.Major, $oldVersion.Minor, ($oldVersion.Build + 1)

$newVersion

Output:

1.44.5
Theo
  • 57,719
  • 8
  • 24
  • 41