NPM with NuGet package auto versioning - release

Our Goal is to have Auto versioning for npm and NuGet packages in release definition of Azure Pipelines
As of now we are using the tokenization task based on the rev value we replacing the version numbers in both nuspec and package.json files.
So we getting the version numbers like 1.0.1, 1.0.2….. like this and auto versioning achieved in release definition
But the problem is whenever the release fails we are losing those numbers as our version numbers because rev value is increasing
Example: If my published version of artifacts is 1.0.1..
Next version to be published for me is 1.0.2
But if the 1.0.2 release is failed and if 1.0.3 is succeeded we are getting published number as 1.0.3 here for end user 1.0.2 is missing
Now we need the help to increment my version number based on last successful release or to reset the rev value based on the successful release or to get the published version of artifacts and increase that number
Or any other best practices to accomplish this task will be helpful.
Thank you in advance.

NPM with NuGet package auto versioning
I am afraid there is no such way to accomplish this task directly. Because $(Rev:.r) is the build number on this day. Use $(Rev:.r) to ensure that every completed build has a unique name. When a build is completed, if nothing else in the build number has changed, the Rev integer value is incremented by one. This value stores in database.
As test, I have created a Inline Powershell task to modify the value when build/release task fails.
I use the powershell script Write-Host "##vso[build.updatebuildnumber]$newVersionNumber" to update the build.updatebuildnumber (I use build.updatebuildnumber as nuget package version.) and set the option Run this task as Only when a previous task has failed:
To see which variables you can use for build and release pipelines, check these pages: - Build variables - Release variables.
Following is the powershell scripts to modify the build.updatebuildnumber:
$vstsCurrentVersionNumber = $Env:BUILD_BUILDNUMBER
$currentVersionNumber = $vstsCurrentVersionNumber.Split(".")
$revisionNumber = $currentVersionNumber[3]
$newRevisionNumber = [int]$revisionNumber -1
$newVersionNumber = $currentVersionNumber[0] + "." +
$currentVersionNumber[1] + "." + $currentVersionNumber[2] + "." +
$newRevisionNumber
$env:VersionNumber = $newVersionNumber
Write-Host "Update Build Number To: $newVersionNumber"
Write-Host "##vso[build.updatebuildnumber]$newVersionNumber"
Indeed, if the build/release task failed, the build number will be modified at this building.
However, when we execute the build/release next time, the buildnumber/$(Rev:.r) still increase based on the last failed build result:
As workaround, we could set a value for the nuget package version, like 1.0.0. And add a Inline Powershell task to increase the value of the version by one each time, when we successfully build/release. Do not execute Inline Powershell task when the build/release fails.
Hope this helps.

Related

Azure Pipelines - Setting Custom Variable to Build Number

In my Azure Build Pipeline (classic, not YAML) I set my build number to be the branch name and then a revision number variable. This was my process for that:
Pipelines -> Pipelines -> {my pipeline} -> Edit -> Options -> Build Number Format
$(SourceBranchName)$(Rev:.r)
In my testing, that works great.
Now, in my Release Pipeline, the first script I run is a PowerShell script that takes the build number, and applies it to a local variable (MyBuild) I created. The script is as follows:
Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
$buildNumber = $Env:BUILD_BUILDNUMBER
$pipeline.variables.MyBuild.value = $buildNumber
This variable is used later in the pipeline to create a folder that houses my release files.
$(BuildDirectory)/$(MyBuild)/Debug
For some reason, my variable is always one build behind. For example, if my build number is master.5, the folder that is created by my Release Pipeline is master.4. I have tried changing the order my scripts are in the pipeline, but that doesn't solve anything. It is weird because my Build Pipeline is correct (always named properly, ex. master.1, master.2, master.3, etc.) but my Release Pipeline variable is always one revision behind.
Powershell script to update the custom build number
- powershell: |
[string]$version="$(Build.Repository.Name)_SomeCustomData_$(Build.BuildId)"
Write-Output "##vso[build.updatebuildnumber]$(Version)"
displayName: Set Build Number
I tested it and it works well. Below is my reproduction, you can refer to:
In release pipeline :
Write-Host '##vso[task.setvariable variable=MyBuild]$(Build.BuildNumber)'
md $(Agent.ReleaseDirectory)/$env:MyBuild/Debug
Select build source as release artifact, default version select Latest, enable Continuous deployment trigger. This creates a release every time a new build is available.
Test reuslt:
In addition, the point I am confused about is how do you use the $(BuildDirectory) in the release pipeline? Agent.BuildDirectory:
The local path on the agent where all folders for a given build pipeline are created. This predefined variable should not be available in the release pipeline, we should use Agent.ReleaseDirectory.You can refer to predefined variable.

Azure Release Pipeline - Variable for 'Triggered' Branch Name

So I have been working off of master for a while, and just recently added a 'release' branch that I will be working off of from now on.
In my Release Pipeline I have a PowerShell script that sets a custom variable using predefined variables.
$branchName = $Env:BUILD_SOURCEBRANCHNAME
$buildNumber = $Env:BUILD_BUILDNUMBER
$release = $branchName + "." + $buildNumber.ToString()
$pipeline.variables.NameVar.value = $release
If I push code to my release branch, this script will run at the end of my pipeline, and the variable should be changed to release.xxxx, but it is changed to master.xxxx.
Is there a reason the build variable build.sourcebranchname does not return my release branch name, and instead returns master? The build.buildnumber variable returns the correct value.
Try to go to Get sources and check whether you select the correct branch.
I've tested your script and it returned expected result:
So I figured out my issue. After adding the new release branch, I needed to edit my build pipeline to setup multiple branches. Basically following this doc from Microsoft.
Adding release/* as a branch filter allowed the build pipeline to build on the release branch, and not just the master branch. From that point on, when I used the build variables in my release pipeline, they all returned the proper value.

How to set up automatic nuget version increments

In my release pipeline for a dotnet core project, I want to increment the assembly version automatically so I don't need to update it manually each time. This is so my Nuget version is increased every time.
At the moment I'm using the dotnet pack command and adding the build number at the end using the "Automated Package Versioning" set to "Use Environment Variable: Build.BuildNumber". Then I set the "Option > Build Number Format" to "1.0.$(BuildID)". First, I tried setting the attribute of the .csproj file to 1.0.$(BuildID), but the pipeline did not pick that up.
The problem is that I have to edit my build pipeline every time I want to adjust my major or minor semver version. Yet with the teams, we agreed not to put build pipeline config in source control (yaml files). Is there a way we can put a part of the build pipeline in a yaml file so that we can override parts of the configuration?
For example: I could set the "Build Number Format" to "$(Major).$(Minor).$(BuildID)" and then the partial yaml could override the Major and Minor variables.
How to set up automatic nuget version increments
If you want to automatic nuget version increments, you could use the BuildNumber $(Rev:r) instead of $(BuildID):
Run (build) number:
$(Rev:r)
2 (The third run on this day will be 3, and so on.)
Use $(Rev:r) to ensure that every completed build has a unique name.
When a build is completed, if nothing else in the build number has
changed, the Rev integer value is incremented by one.
If you want to show prefix zeros in the number, you can add additional
'r' characters. For example, specify $(Rev:rr) if you want the Rev
number to begin with 01, 02, and so on.
So, you could set the Build Number Format to $(Major).$(Minor)$(Rev:.r).
Hope this helps.

Unable to use Custom Pipeline Variable for Release Name

I've created a powershell script that updates a Pipeline Variable during a Release Pipeline. It takes the custom variable and updates it with a new version using semantic versioning with every run.
I've tried to add this custom variable as the Release Pipeline but keeps on giving me an error "Names of releases from this pipeline will not be unique. Use pre-defined variables to generate unique release names."
I've tried setting the variable to "Settable at Release" and putting the scope to "Release"
Does anybody perhaps know if there is a way to let the release pipeline know this is a dynamic variable that changes?
The only other option is to add the revision number to it $(versionnumber)$(rev:.r)
use Custom Pipeline Variable for Release Name
For this issue ,I think it not feasible to achieve it. Release name must be a unique name,
the $(rev:r) token can ensure that every completed build/release has a unique name because it's adding a incremental number for each release. When a build/release is completed, if nothing else in the number has changed, the Rev integer value is incremented by one. So, basically we cannot achieve that without using $(rev:r), unless you can defined a token which has the same function with $(rev:r).
In addition,you can also use $(Build.BuildNumber) or $(Release.ReleaseId) which are also unique.
For the similar issue,please refer to this case .

How can I add some selective features/ subfeatures to a new release build through Automation Interface

I am using Install Script in Install Shield 2013 on Windows 7, Lang Used C#.
I have a project and it has some features and sub features added to it. Now I want to build a new release using Automation Interface need to add some selective features/ subfeatures to this release so that the original features remains unaltered.
We can pass the New release name and features required in this release using Command Line.
How can I add selective features supplied as command line arguments to my release. Is there any predefined Object/function/Method for this. Please advise.
Need to achieve this in Install Script only.
We can do so by using IncludeInBuild() property of ISWiFeature. It alters the default IncludeInBuild value of a feature.
To make it temp store the current values of the features to be altered in a list , then build a new release. After making new release, once again assign the value stored in list to the altered features.

Resources