Associating multiple work items to a commit in DevOps
Summarize
Summary of Associating multiple work items to a commit in DevOps
ServiceNow DevOps supports associating multiple work items to a single commit across Azure DevOps, Bitbucket, GitHub, and GitLab. This capability helps you link development work directly to work items, improving traceability and alignment with your organization's processes.
Show less
Key Features
- Multiple Work Item Support: You can associate multiple work items in one commit message using supported syntax patterns.
- Customizable Commit Message Parsing: Commit message formats for identifying work items can be tailored by extending the
DevopsCommitMessageParserSNCscript include in the System Definition > Script Includes module. - Out-of-the-Box Supported Formats:
- Colon pattern: e.g.,
STRY1,STRY2: Additional bug fixes - Hash pattern: e.g.,
Fixes for #STRY1, #STRY2, #STRY3orFixes for AB#123 - Jira pattern: e.g.,
JRA-123 fixed
- Colon pattern: e.g.,
- Extendable Parsing Logic: You can add new regular expressions and logic in the
DevopsCommitMessageParserscript include to support additional or custom commit message formats, such as work items enclosed in square brackets. - User Interface Support: Work items can also be linked to commits directly via the Azure DevOps UI. Associated work items are visible on DevOps Commit records and within the Pipeline UI for easy tracking.
Practical Application for ServiceNow Customers
By leveraging this feature, you can:
- Ensure comprehensive linking of all relevant work items to a commit for accurate progress tracking and reporting.
- Customize commit message parsing to align with your organizational conventions without modifying the core system.
- Use enhanced visibility of associated work items in the DevOps and Pipeline UIs to improve collaboration between development and IT service management teams.
This integration helps maintain synchronization between development work and ServiceNow work items, enhancing traceability, auditability, and process compliance within your DevOps workflows.
Multiple work items for a commit are supported in DevOps for Azure DevOps, Bitbucket, GitHub, and GitLab.
Work item syntax in the commit message can be customized to reflect the processes in your organization using the DevopsCommitMessageParserSNC script include in the System Definition > Script Includes module.
/**
* Supported patterns
* Colon pattern
* Sample supported formats:
* 1. STRY1,STRY2: Additional bug fixes
* 2. STRY1 , STRY2 : Additional bug fixes
* 3. STRY1, STRY2 : Additional bug fixes
* Hash pattern
* Sample supported formats:
* 1. Fixes for #STRY1, #STRY2, #STRY3
* 2. Fixes @$#3 and #1 work item
* 3. Fixes for #STRY1 #STRY2 #STRY3
* 4. Fixes for AB#123
* Jira pattern
* Sample supported formats:
* 1. JRA-123 fixed
* 2. JRA-123 JRA-234 JRA-345 resolved
*/var DevopsCommitMessageParser = Class.create();
DevopsCommitMessageParser.prototype = Object.extendsObject(DevopsCommitMessageParserSNC, {
initialize: function() {
DevopsCommitMessageParserSNC.prototype.initialize.call(this);
this._customPattern = /\[(.*?)\]/g; // The regex pattern to match the words written inside square brackets.
// Example commits message to match this custom pattern is : "[STRY1], [STRY2] Additional bug fixes"
},
getWorkitemsFromCommitMessage: function(message, branchName) {
var workitems = [];
// We first call the getWorkitemsFromCommitMessage method from the parent class to get the matching workitems ids for OOB formats
var defaultWI = DevopsCommitMessageParserSNC.prototype.getWorkitemsFromCommitMessage.call(this, message, branchName);
if (!gs.nil(defaultWI) && defaultWI.length > 0) {
workitems = workitems.concat(defaultWI);
}
// Now call your custom method that returns an array of workitem native IDs matching custom pattern
var customWI = this.getWIFromCustomPattern(message);
if (!gs.nil(customWI) && customWI.length > 0) {
workitems = workitems.concat(customWI);
}
// getUniqueWorkItems method from parent class removes duplicates from the workitems array
workitems = this.getUniqueWorkItems(workitems);
// return the final list
return workitems;
},
getWIFromCustomPattern: function(message) {
var wi = [];
var l;
var match;
var matches = message.match(this._customPattern);
if (gs.nil(matches))
return wi;
for (var i = 0; i < matches.length; i++) {
l = matches[i].length;
match = matches[i].substring(1, l - 1); // trim the brackets
wi.push(match);
}
return wi;
},
type: 'DevopsCommitMessageParser'
});Linking work items to a commit using the Azure DevOps user interface is also supported in DevOps.
You can view the list of associated work items in the DevOps Commit record, and in the Pipeline UI.