Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use git tag or package.json version as Release name in VSTS

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?

like image 754
Th3S4mur41 Avatar asked May 23 '18 20:05

Th3S4mur41


People also ask

How do you tag a release on Azure DevOps?

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.

How do I automatically update package JSON?

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).

How do I tag a commit in DevOps?

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.

How do I add tags to Azure DevOps?

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.


1 Answers

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:

  1. 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).

    enter image description here

  2. 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.

    • To get the tag name, you can use the git command git tag --points-at HEAD.
    • To get the package.json version, you can use powershell script to search the line start with "version" etc.
    • To update the group variable, you should use the REST API Variablegroups - Update.
  3. 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.

    enter image description here enter image description here

Now when the release is triggered, it will use the git tag or package.json version with revision for the release name.

like image 193
Marina Liu Avatar answered Oct 17 '22 01:10

Marina Liu