I have a CI task in VSTS for automatic build and test and an automatic release definition for the 'Latest from build definition default branch with tags'.
The release name format is currently set to the default value $(rev:r) which just sets an increasing number that has no relation to any real version.
I'd prefer to use the version of my app as a release name either from the package.json or from the git tag created by yarn when I update the package version. Is there any way to achieve this?
Use tags in release pipelinesGo to your release pipeline and edit the Pre-deployment conditions for your stage. In this example, I want to do an automatic release of Prod stage once the build from branch main and with tag prod is created. Automatic release once build from main branch with prod tag is created.
Run npm update to automatically update my packages to the latest versions From docs: > This command will update all the packages listed to the latest version (specified by the tag config), respecting the semver constraints of both your package and its dependencies (if they also require the same package).
Select a branch to view history, right-click a commit, and select New Tag. In the Create a new tag dialog, enter a Tag name only for a lightweight tag or a Tag name and Tag message for an annotated tag. Select Create.
Adding Tags in Azure DevOps when the build is success. By default it will take the tag name as $(build. buildNumber), here I want to add the tag name as a custom one which is mentioned in the txt file. For example, I have mentioned tag name as 1.2.
You can not use git tag or package.json version for release name directly, since only part of predefined variables can be used for release name, and variables can not persist between build and release.
But you can use group variable for assistance: update group variable value with git tag or package.json version at the end of your CI build, and use the group variable as the release name. Detail steps as below:
Add variable group
In Build and Release Hub -> Library Tab -> Add Variable group (such as release name
) with a variable (such as tag
) with any initial value (such as 0
).
Change the group variable in CI build
You can add a PowerShell task to change the group variable with git tag or package.json version.
git tag --points-at HEAD
."version"
etc.Use the group variable in release
To apply the git tag or package.json version in release name, you can change your release definition as below:
Release definition -> Variables Tab -> Variable groups -> Link variable group -> select the variable group -> Options Tab -> specify the group variable tag with revision as the release name.
Now when the release is triggered, it will use the git tag or package.json version with revision for the release name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With