Skip to content

Instantly share code, notes, and snippets.

@PathriK
Forked from IlyaFinkelshteyn/UpdateBuildVersion.ps1
Created January 5, 2017 02:25
Show Gist options
  • Save PathriK/9b9cd9b246ee6daf2f25a4c5aff0f19a to your computer and use it in GitHub Desktop.
Save PathriK/9b9cd9b246ee6daf2f25a4c5aff0f19a to your computer and use it in GitHub Desktop.
$token = $env:API_TOKEN #should be defined as scure variable
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
$apiURL = "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG"
$history = Invoke-RestMethod -Uri "$apiURL/history?recordsNumber=2" -Headers $headers -Method Get
$pomVersion = ([xml](Get-Content .\pom.xml)).project.version
if ($history.builds.Count -eq 2)
{
$previousVersion = $history.builds[1].version
$previousMajor = $previousVersion.Substring(0, $previousVersion.LastIndexOf("."))
Write-Host "Previous major version: $previousMajor"
Write-Host "Current version from pom.xml: $pomVersion"
if ($previousMajor -ne $pomVersion)
{
Write-Warning "Major version has been changed, resetting build number"
#reset current build number to 1 and next one to 2
$env:APPVEYOR_BUILD_NUMBER = "1"
$body = @{
nextBuildNumber="2"
}
$body = $body | ConvertTo-Json
Invoke-RestMethod -Uri "$apiURL/settings/build-number" -Headers $headers -Body $body -Method Put
}
}
Update-AppveyorBuild -Version "$pomVersion.$env:APPVEYOR_BUILD_NUMBER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment