Reputation: 229
Incremental Build Number for .NET Core via Azure DevOps
Hi i need to automatically add and increment the build version number for my project , thought adding power shell scripts in pipeline, though i have a sample script for calculate the number of days from 1/1/2000. i need script to add the iteration number - c# via devops.
similiar script calculate the number of days from 1/1/2000.
$baseDate = [datetime]"01/01/2000"
$currentDate = $(Get-Date)
$interval = NEW-TIMESPAN –Start $baseDate –End $currentDate
$days = $interval.Days
Write-Host "Generating Build Number"
$baseDate = [datetime]"01/01/2000"
$currentDate = $(Get-Date)
$interval = NEW-TIMESPAN –Start $baseDate –End $currentDate
$days = $interval.Days
Write-Host "##vso[task.setvariable variable=buildNumber]10.0.$days.1024"
it could be great if i get any information related to this.
Upvotes: 0
Views: 1838
Reputation: 8343
Iteration is not a unique value, so there is no simple answer.
It depends how you determine which Iteration are you on and it may be different from one project to another, from one team to another.
You may query the Iterations REST API using the current date as pivot, but I will not recommend this. What if you run the build on an older version of code? It will pick the iteration from today, not from the code timestamp.
The best approach is to the source code version, you have the handy Build.SourceVersion
variable, and a good build report linking all information together (look at at GenerateReleaseNotes Task for example).
Upvotes: 1