Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/cdf6e8185ce00baa74b57699a665bb14 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/cdf6e8185ce00baa74b57699a665bb14 to your computer and use it in GitHub Desktop.
#WARNING: this may work unpredictable with parallel build of the same project (parallel jobs in matrix are fine)
#Note $separator variable. If "-" can be used earlier in build version, replace it to something unique
version: 0.1.{build}
environment:
API_TOKEN:
secure: SlDEDtAKuvsy+VErEuc/4DxdhPeKu2WRqvYzEh/fiH4=
for:
-
branches:
only:
- master
init:
- ps: |
echo "common init"
init:
- ps: |
echo "common init"
$token = $env:API_TOKEN #should be defined as a secure variable
$separator = "-"
$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
if ($history.builds.Count -eq 2) {
$s = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings" -Headers $headers -Method Get
$s.settings.nextBuildNumber = ($s.settings.nextBuildNumber - 1)
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/projects' -Headers $headers -Body ($s.settings | ConvertTo-Json -Depth 10) -Method Put
$previousVersion = $history.builds[1].version
if ($previousVersion.IndexOf("$separator") -ne "-1") {$previousVersion = $previousVersion.SubString(0, $previousVersion.IndexOf("$separator"))}
Update-AppveyorBuild -Version $previousVersion$separator$((New-Guid).ToString().SubString(0,8))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment