Azure Pipeline - Get associated git TAG? - azure-devops

On my pipeline, I can retrieve the build number using the variable RELEASE.ARTIFACTS.MyPipeline_BUILDID. But I was wondering, how can I get the TAG associated with the build.
It is visible within the pipeline like:
is there a way to capture it in a variable within the yml so I properly concatenate it like:

You can use the variable SourceBranch:
The branch of the triggering repo the build was queued for.
When your pipeline is triggered by a tag: refs/tags/your-tag-name
So, in the release the variable will be RELEASE.ARTIFACTS.MyPipeline_SOURCEBRANCH.

Related

How to Tag a branch Automatically in Azure DevOps using extension (Tag/Branch Git On Release)

With Azure DevOps release pipeline I'm planning to tag my brach Automatically by using the below extension which was created by Micheal Barry Tag\Branch Git on Release. See the below image:
I'm a bit wondering how to customize Tag name as UAT_$(date:yyyyMMdd)$(Rev:.r). Since this has limited documentation, this is how I try to add(See below)
How can I achieve this? Also, I'm more interested in how to fill these advanced options for this extension.
The $(date:yyyyMMdd)$(Rev:.r) is only supported in BuildNumber (Options=>Build Number Format) and ReleaseNumber (Options=>Release Name format). So if you put $(date:yyyyMMdd)$(Rev:.r) directly in Static Tag Name, the task can't evaluate its value.
Here're several directions to do what you want:
Use $(date:yyyyMMdd)$(Rev:.r) as release name format.
Then use UAT_$(Release.ReleaseName) in Static Tag Name input.
The result:
PS: If you set build pipeline as release pipeline's artifact source, you can also use $(Build.BuildNumber)/$(Build.DefinitionName) in your Release name format.
2.If you prefer to use Release-$(date:yyyyMMdd)$(Rev:.r) as release name format. Now since what you want is UAT_xxx, you need to use the Regex option:
Assuming your release name's instance is Release-20200518.5, now the tag would be UAT_20200518.5 if you configure the task following my inputs above.
In addition:
When release name format is $(date:yyyyMMdd)$(Rev:.r), you releases would be:
You can choose to use the Static Tag Name, check #1 above.
And when the name format is Release-$(date:yyyyMMdd)$(Rev:.r), you releases would be:
You should use regex option in that third-party task, check #2 above. About what is Regex see here, also there's many documents/blogs online about Regex topic...
You are using the wrong task in your pipeline. Would suggest using the git tag task, it works just fine to me and you can use your naming in the tag field
Git Tag Task
I find this extension much easier to setup and its satisfying our needs. So basically my git tag=assembly version. I am doing this every time we have a release on production environment(change assemblyInfo information and store that in Variable in the build definition). There are set of tasks on the marketplace to allow read from asemblyInfo and write to it. For the git tag task i just use the previously set Tag variable which basically is incremented by one every new release. You can check more in the pictures bellow
So i am actually just adding simple tag to mirror my assemblyVersion but in the tag message i am also adding my build informations that looks like this $(build.buildNumber)-$(Tag)
If you want to have a deeper look into azure devops predefined variables you can do that here Use predefined variables

Can I programmatically set an overridable default value for a variable in an Azure DevOps Release Pipeline?

I have a variable called some_var in an Azure DevOps release pipeline. I'd like to set the default at release time. But I want to set it programmatically based on the contents of a file in the artifact drop folder. But I still want the user to be able to overwrite the dynamically set value at the time they're creating the release.
So the end-user behavior would be that they (1) navigate to the Release and (2) click "Create New". The dialog comes up with the some_var variable already set to a value stored in a text file. But, because the variable is set to be settable at runtime, they can also modify the variable value before they click the button to create the release.
Is there any way I can dynamically populate (before the release is created) the some_var value and still make it editable by the person creating the release at crate-time.
The dialog comes up with the some_var variable already set to a value
stored in a text file.
We don't support this out-of-box feature. The release pipeline variable can't dynamically
populate the some_var value before the release is created.
Possible workaround:
Your original purpose is to set it programmatically based on the contents of a file in the artifact drop folder. So I assume you may have a build pipeline which this release depends on, and your actual need is to:
Once the build pipeline is finished, the default value of some_var in release pipeline should set as the value from build pipeline.
You can consider adding a powershell task in the end of build pipeline that release depends on, calling the Definitions-Update rest api in ps script to set the default value of some_var in Release pipeline depending on content of Build pipeline. Similar issue you can check this one.
And if the pipeline variable some_var is settable at release time:
The whole behavior would be (assuming we want to pass the buildID in Build to the some_var in Release):
1.The build pipeline executes well, its last Powershell task updates the some_var to some_var = 15.
2.When I click the Create release button, the dialog comes up with some_var variable already set to a value from Build pipeline 15.
3.Now, because the some_var enables settable at release time, we can easily modify it before clicking the Create button.
Hope it helps :)

How do I make a release pipeline in Azure DevOps that creates a GitHub release every time?

I get this warning when the pipeline runs:
Release will not be created as the tags for the target commit do not match with the given tag pattern.
Thing is, the Tag Pattern property of the GitHub release is blank; I'm not setting any particular tag pattern. How do I skip this warning so the release can be created every time the pipeline runs?
How do I make a release pipeline in Azure DevOps that creates a GitHub release every time?
I could reproduce this issue on my side, if I leave the Tag Pattern property of the GitHub release is blank.
That because this property is Required. Check the GitHub Release task:
Tag source (Required) Configure the tag to be used for release
creation. The 'Git tag' option automatically takes the tag which is
associated with this commit. Use the 'User specified tag' option in
case you want to manually provide a tag.
As the description above, the 'Git tag' option automatically takes the tag which is
associated with this commit.
So, if we leave that property Tag Pattern is blank, the value is null, but the commit id is not null, then you will get this error. Check my detailed build log:
To resolve this issue, we could give the Tag Pattern with the commit ID. Or you could use the another option User specified tag, then you can manually provide a tag, like release-v1.0.
As test, it works fine on my side.
Update:
but I want the pipeline to run every time someone pushes or merges code into the master branch; I don't want to have to specify a tag for each commit
If you do not want to have to specify a tag for each commit, you can use counter expressions in Variables, like:
variables:
MajorVersion: 1
MinorVersion: 0
InitialReleaseTagNumber: 1
IncrementReleaseTagNumber: $[counter(variables['InitialReleaseTagNumber'], 0)]
Then we set v$(MajorVersion).$(MinorVersion).$(IncrementReleaseTagNumber) following in the tag option:
So, the value of the tag will increase by 1 once the build runs.
Hope this helps.

How not to have 'version=GBmaster' in Azure DevOps links

Azure DevOps urls to files and to wiki entries contain &version=GBmaster and &wikiVersion=GBwikiMaster respectively.
Is it possible to configure DevOps not to append it?
Today I get:
https://myorg.visualstudio.com/MyProject/_git/MyRepo?path=%2Fsrc%2FMyFile.cs&version=GBmaster
https://dev.azure.com/rbtech/Redback/_wiki/wikis/MyOrg.wiki?pagePath=%2MyPage&pageId=204&wikiVersion=GBwikiMaster
I wish for:
https://myorg.visualstudio.com/MyProject/_git/MyRepo?path=%2Fsrc%2FMyFile.cs
https://dev.azure.com/rbtech/Redback/_wiki/wikis/MyOrg.wiki?pagePath=%2MyPage&pageId=204
This is the default behavior of AzureDevop basically &version/ &wikiversion is denoted which branch the code/wiki is showing in the UI. Even if you don't provide the Version AzureDevOps will automatically append it to indicate which branch is chosen.
Let's say in your repo you have multiple branches means like master/ develop then based on the branch you choose the &version will change automatically like &version=GBmaster or &version=GBdevelop if you don't provide the default branch will be appended in the query.
Is it possible to configure DevOps not to append it?
No, there isn't a way to configure it. It's the expected behavior as Jayendran described, it's a tag which marks the file version from which branch.
If you want to see the contents of the files without the &version=GBmaster, then you can try call the REST API : Items - Get
For example:
https://{organization}.visualstudio.com/{Project}/_apis/git/repositories/{Repository ID}/items?path=WAP/WAP.Tests/Properties/AssemblyInfo.cs

Build pipeline - Get title of check-in that triggered pipeline

I'm creating a new build pipeline, it will be triggered on a new check-in on a specific branch on a TFVC repository. I want to get the title of the check-in every time the pipeline triggers and store it in the variables.
Additionally, after getting the title I want to perform some checks and depending on the result ( e.g. title matches a specific template) either stop the build pipeline or move on to the next steps
I've looked in Variables and Triggers tabs, but I didn't find anything useful. I've also looked in the predefined variables, but I didn't find anything related to my issue either.
You can try this variable Build.SourceVersion to get the number and Build.SourceVersionMessage to get the comments.
Build.SourceVersionMessage The comment of the commit or changeset. Note: This variable is available from TFS 2015.4.
See also: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml