Skip to content

Instantly share code, notes, and snippets.

@rosberglinhares
Last active April 10, 2018 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rosberglinhares/bdb5c16be1172862db1bc0786dc690c5 to your computer and use it in GitHub Desktop.
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
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