Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a tag during a release pipeline in azure-devops

Tags:

azure-devops

Setup

When running a release pipeline, i do

  1. consume a artifact of build-pipeline projectA ( which uses the repository projectA )
  2. this artifact is a node package build
  3. I will inject (re-version) the package version ( using a pipeline variable VERSION ) and then release to the npm registry as the final step

Goal Beside all the build / release tasks work, we have one specific issue, and that is the missing checkout of the repository in the release step. We do not want to have the repository for actually "rebuilding" something, but for tagging the commit we build using the variable $VERSION and pushing it the the repository.

Issue

I do know how to get the commit hash of our source project repository build ( env var Build.SourceVersion ) and the repository name ( env var Build.Repository.Name ), but i do not understand how i actually would get the repository checked out since i miss the credentials.

Right now i have the repository on Github ( private repository ), might though also move to a private Bitbucket.

The actual concrete question is, how would one checkout the repository with

  • either using a static name
  • or using Build.Repository.Name

And with

  • either a generic task ( some git repo )
  • or a specific SCM repo task ( like checkout-from-github or checkout-from-bitbucket using some sort of service connection ).

I assume i need some sort of credentials, in my current case it would be some sort of Github access token or similar ( oAuth )?

like image 810
Eugen Mayer Avatar asked Jan 28 '20 17:01

Eugen Mayer


People also ask

How do you add tags to pipeline release?

Go to Variables/Pipeline variables tab. Add your variable, for example EnvironmentTag and add default value. Select Settable at queue time to make sure that you can change it when you are scheduling your build.

How do I create tags in Azure DevOps?

Select Create Tag from the Tags view in the web portal to create a new annotated tag. Specify a Name, select the branch to Tag from, enter a Description (required since you are creating an annotated tag), and select Create. The new tag is displayed in the tag list.


1 Answers

So I am not sure if you are using GUI based Releases or the newer multi-stage pipeline feature.

For the classic release GUI you can add an Artifact that is your Github repository from the release definition editor. When you go to add the Artifact it will ask you to configure the service connection back to github, or you can use an existing connection.

In the release definition editor at the Agent Job level, you will want to be sure to check the Allow scripts to access the OAuth token

enter image description here

From there navigate to the release directory that contains your repository and then you can push a tag.

cd $(Agent.ReleaseDirectory)\_enufacas_azureDevOps.Postman
git tag  Rel-$(Build.BuildNumber)
git push --tags

The multi-stage pipeline also has a similar path using the checkout task

like image 93
Eric Smith Avatar answered Oct 13 '22 09:10

Eric Smith