Last active
April 10, 2018 19:36
-
-
Save rosberglinhares/bdb5c16be1172862db1bc0786dc690c5 to your computer and use it in GitHub Desktop.
Powershell script to increment and get the assembly version to be used with the EnvInject Jenkins plugin
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
Param ( | |
[Parameter(Mandatory=$true)] | |
[string] $AssemblyInfoPath, | |
[string] $PropertiesFilePath = 'EnvInjectProperties.txt', | |
[string] $PropertyName = 'NEXT_VERSION' | |
) | |
$ErrorActionPreference = 'Stop' # Stops executing on error instead of silent continue. | |
Set-StrictMode -Version Latest # Enforces coding rules in expressions, scripts, and script blocks. Uninitialized variables are not permitted. | |
$fileContent = Get-Content $AssemblyInfoPath | Out-String | |
$assemblyVersionPattern = 'AssemblyVersion\("(\d+\.\d+\.\d+\.\d+)"\)' | |
$currentVersionStr = [RegEx]::Match($fileContent, $assemblyVersionPattern).Groups[1].Value | |
$currentVersion = New-Object Version($currentVersionStr) | |
$newVersion = New-Object Version($currentVersion.Major, $currentVersion.Minor, $currentVersion.Build, ($currentVersion.Revision + 1)) | |
Add-Content $PropertiesFilePath "$PropertyName=$newVersion" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment