Automating Work Item Access from Git Branches
Automating Work Item Access from Git Branches
Automating Work Item Access from Git Branches
Streamlining Azure DevOps integration with local development environments helps maintain context and reduces context-switching during task transitions.
The Branch-Work Item Discovery Challenge
- Lost references: Difficulty tracing work items across multiple feature branches
- Manual searching: Time-consuming navigation in Azure DevOps portal
- Context switching: Breaking development flow to find requirement details
PowerShell Automation Solution
Script functionality:
- Gets current Git branch name using
git rev-parse
- Extracts work item ID using regex pattern
[TF](\d+)
- Constructs Azure DevOps URL dynamically
- Opens web browser directly to the work item
Implementation code:
1
2
3
4
5
6
7
function Open-WorkItem {
$branchName = git rev-parse --abbrev-ref HEAD | ForEach-Object { $_.Trim() }
if ($branchName -match '[TF](\d+)') {
$workItemId = $matches[1]
Start-Process "https://dev.azure.com/ProjectName/Q/_workitems/edit/$workItemId"
}
}
Component | Function |
---|---|
[TF] | Matches ticket type (Task/Feature) |
(\d+) | Captures numeric work item ID |
$matches[1] | Extracts first regex group |
Start-Process | Launches default browser |
Configuration Guide
- Add function to PowerShell profile (
Microsoft.PowerShell_profile.ps1
) - Ensure branch naming contains work item ID prefix:
- Format examples:
T1234-feature-description
orF5678-bugfix
- Format examples:
- Save and reload profile:
. $PROFILE
Usage Workflow
- Checkout feature branch:
git checkout T7890-new-api
- Execute command:
Open-WorkItem
- Browser opens directly to work item #7890 ```
This post is licensed under CC BY 4.0 by the author.