Created
February 18, 2020 09:14
-
-
Save GeradeDev/c54c579cb6efe1c62071e24ba3309113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$packageName = Get-VstsInput -Name 'packageName' -Require | |
$maxIncrement = Get-VstsInput -Name 'maxIncrement' -Require | |
$pipelineVariable = Get-VstsInput -Name 'pipelineVariable' -Require | |
Write-Host "The Package in use is: " $packageName | |
Write-Host "The Max Increment version is: " $maxIncrement | |
#Add Package Source | |
Write-Host "Adding Nuget Package Source" | |
Register-PackageSource -Name NuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet | |
#Get the current version for the Package | |
$currentVersion = Find-Package $packageName -Source NuGet | Select-Object -ExpandProperty Version | |
#Split version | |
$Major = $currentVersion.Split(".")[0] -as [int] | |
$Minor = $currentVersion.Split(".")[1] -as [int] | |
$Patch = $currentVersion.Split(".")[2] -as [int] | |
#Set new/next version of Package | |
$newVersion; | |
if(($Patch + 1) -eq $maxIncrement) { | |
#Increment the Minor version and reset patch version to 0 | |
Write-Host "Patch version value has been reached the Max Increment value supplied." | |
Write-Host "Reset the Patch version to 0 and Increment the Minor version by 1" | |
$Minor = ($Minor = + 1); | |
$Patch = 0; | |
}else { | |
#Increment the Patch version | |
Write-Host "Patch version value has not been reached the Max Increment value supplied. Only Increment Patch version." | |
$Patch = ($Patch + 1); | |
} | |
$newVersion = ($Major, $Minor, $Patch) -Join "." | |
# Output the message to the log. | |
Write-Host "Old Version of Package: " $currentVersion | |
Write-Host "New Version for Package: " $newVersion | |
Write-Host "Set environment variable to ($newVersion)" | |
# Output the new version to be used by the subsequent tasks | |
Write-Output "##vso[task.setvariable variable=$pipelineVariable;]$newVersion" | |
Write-Host "New Package version $newVersion" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment