Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AzureDevOps - Link git commit or branch to work item via command line

I've worked on projects with a Jira integration where I simply had to include the ticket number in the commit or branch name and that work would automatically link with the ticket in Jira. Exe:

git commit -am '123 some commit'

And on the ticket you'd see a link to the commit.

How can I do that with Azure Dev Ops?

I know how to manually do it via Visual Studio or in the ticket itself, but I want to do it through the command line only.

like image 952
JDillon522 Avatar asked Feb 07 '19 16:02

JDillon522


People also ask

How do you link work items in Azure DevOps pull request?

You can link work items to existing builds from the Add link dialog. From the Links tab of a work item, choose Add link>Existing item. From the Add link dialog, choose one of the build link types—Build, Found in build, Integrated in build— and specify the build number.

Which link type is used to associate source code with work items?

GitHub link types are system-defined link types. They support linking work items to GitHub objects as shown in the following image.

How do I commit to another branch in Azure DevOps?

Switch to the Azure DevOps browser tab. Navigate to Repos | Branches. Click New branch. Enter a name of “release” for the new branch.


2 Answers

You can link a work item in Azure Boards to a commit in Azure Repos by specifying the work item ID after a pound sign. Eg, to update work item #3, you need to mention #3 in the commit message. (The pound sign - # is required, it won't parse bare numbers and try to link work items.)

For example:

git commit -m"Update bug #3" 

Produces a bidirectional link between the commit and the work item. You can see this in the commit details, in the work item tab:

Commit details

And you can see this in the work item details, in the "Development" section:

enter image description here

like image 111
Edward Thomson Avatar answered Sep 22 '22 06:09

Edward Thomson


For those wondering why their commits aren't auto-linking to work items for some of their repositories - this is a feature you can turn on per repository:

Within Project Settings | Repositories navigate to the repository that isn't auto linking, and then under Settings enable "Commit mention linking" (and potentially "Commit mention work item resolution"):

Repository Settings - Enable Commit Mention Linking

You may find that this is disabled by default for Forks, whilst it's enabled by default for brand new repositories.

There is no way to automatically link branches to work items; unless you create the branch from the work item directly, using the "New Branch" button or "create a branch" link:

Create branch link

Create branch dialog
Note: This link only exists if there are no other Development links on the work item - you have to use the "Add Link" dialog after that.

There is an open ticket for that functionality: https://developercommunity.visualstudio.com/t/automatically-link-a-work-item-to-branches-when-co/809745

like image 28
Zhaph - Ben Duguid Avatar answered Sep 20 '22 06:09

Zhaph - Ben Duguid