62

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.

JDillon522
  • 19,046
  • 15
  • 47
  • 81

2 Answers2

84

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

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • this is really cool, so I suppose you need to know the ID of the work item and you can link to it, right? doesnt matter if its a bug or a feature or an epic etc – 4c74356b41 Feb 07 '19 at 16:27
  • 1
    Correct - it doesn't matter what the work item type is. – Edward Thomson Feb 07 '19 at 16:34
  • 4
    Is it possible to do this with branches? I just tried `git checkout -b '#123-tes't` as well as renaming it to `123-test` (removed the hash). – JDillon522 Feb 07 '19 at 16:46
  • 8
    No, unfortunately(?) Azure Repos only parses commit messages for work item "mentions", it doesn't examine branch names. Interesting idea though, I'll talk to the team about it. – Edward Thomson Feb 07 '19 at 16:57
  • 2
    @EdwardThomson Our team relies on having issue id as branch prefix to ensure the sprint lanes are always up-to-date especially when the developer is too excited to write even more code and forgets to click the right buttons or refer issue in commit messages :) Do you have an UserVoice link or similar available for tracking this particular feature request as JDillon522 asked? – Esko Mar 19 '19 at 11:41
  • 1
    @EdwardThomson there are a couple of ideas to implement linking branch names: https://developercommunity.visualstudio.com/content/idea/480092/in-vs-team-explorer-create-branch-based-on-work-it.html https://developercommunity.visualstudio.com/idea/607018/link-to-a-work-item-by-parsing-branch-name.html – Sam Hasler Nov 21 '19 at 10:27
  • 1
    Is it possible to link more than one task? Like using two Ids in the same commit? – Mohamad Mousheimish Apr 01 '20 at 17:46
  • 1
    So what if such a commit *doesn't* create a link? Is there a setting somewhere to activate this automatic linking? – Marc Nov 12 '20 at 16:30
  • 2
    I'm also not getting any linking when I add #ID to my commits – James Joshua Street Apr 12 '21 at 07:44
  • 1
    # sign. In English: "hash", in American "pound". Interestingly enough, the original name for it is actually "octothorpe", possible invented by Don MacPherson, Bell Laboratories, 1968, which is entirely unambiguous and no one will know what on earth you are talking about. In English, a "pound" sign is one of these: £, which is what we use to buy stuff, along with shillings and pence. – Mark Roworth Apr 06 '23 at 09:36
30

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

mkjeldsen
  • 2,053
  • 3
  • 23
  • 28
Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • 1
    Even with those settings on doesn't seem to work in VS2022 17.0.6 – Moon Waxing Feb 10 '22 at 06:41
  • Just realized that this wasn't enabled and many commits aren't linked. Anyway to go through and refresh the links within respective work items once enabled? – TechFanDan Apr 05 '23 at 16:56
  • 1
    @TechFanDan Not automatically I don't think. There are options to do so via the API probably, or you can do it manually by adding a link under the "Development" section. – Zhaph - Ben Duguid Apr 11 '23 at 11:06