Intergrating ITSM and CSM with Azure DevOps Series: Create a Work Item in Azure DevOps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 12:54 AM
Hello!
We were recently asked by a small DevOps team if we could integrate ServiceNow into their tools.
As part of this they wanted the ability to integrate ServiceNow ITSM and CSM with Azure DevOps so that issues and faults could be managed by the DevOps teams in their tool without having to log into ServiceNow.
ServiceNow an OOTB integration but with PPM which was not a good fit for us because we didn’t want or need to spin up PPM just to create a work item in Azure DevOps.
In a series of blogs, I am going to talk about how I built this integration and the challenges I faced
Creating a Workitem in Azure DevOps is super simple.
Azure has some great docs explaining the API’s Available
To send a request to Azure DevOps you will need to following information about the Azure DevOps project you want to communicate with
- Organisation name
- Project name (Our DevOps team call this a board)
- A PAT (how to get a personal access token here)
- Field names in Azure DevOps you want to set (how to find field names link here)
Organisation and project name can be see in the Azure DevOps URL
Once you have all the required information creating a card in Azure DevOps driven by a business rule.
An example of code we can use to create a workitem type of bug can be seen below.
Azure DevOps authenticaiton requires that we send just the password. We achive this below by base64 encoding a colon followed by the PAT token we got from Azure DevOps. In the below code I have shown hard coding the password in the a script but in a real worl example we store the password in an encoded formate using a system property with the type of password
In the below code rather than creating a Rest Message we instantiate a RestMessageV2 class and set all the properties manually for two reasons.
1) we cant store the password in the sys_user table passwords must have a user name
2) we use this intergraiton now for a number of different Azure DevOps boards being able to pass in orgnames, project names and tokens keeps the code resuable
var workItemBody = [{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Short Description from SN task"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Common.Priority",
"from": null,
"value": "3"
},
{
"op": "add",
"path": "/fields/System.History",
"from": null,
"value": "A work note"
}
]
try {
var token = ":" + "{{TOKEN FROM ADO}}"
var orgName = "orgName"
var projectName = "projectName"
var encodedToken = gs.base64Encode(token);
var code;
var returnBody;
gs.info(encodedToken)
var url = "https://dev.azure.com/" + orgName + "/" + projectName + "/_apis/wit/workitems/$bug?api-version=7.0"
r = new sn_ws.RESTMessageV2();
r.setHttpMethod('post');
r.setEndpoint(url);
r.setRequestBody(JSON.stringify(workItemBody));
r.setRequestHeader("Content-Type", "application/json-patch+json");
r.setRequestHeader("Authorization", "Basic " + encodedToken);
var response = r.execute()
returnBody = response.getBody();
code = response.getStatusCode();
} catch (error) {
gs.error("ADO v2_Util_Rest_Message - insertWorkItem " + error);
gs.error("ADO v2_Util_Rest_Message - insertWorkItem " + code);
}
Next blog I will talk about pulling updates from Azure DevOps and keeping ADO and ServiceNow in sync
- 1,409 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2024 11:15 PM
Hey Mate,
This post is definitely helpful - As you have mentioned that you will be posting the link for next post - which will have ADO to ServiceNow integration steps - Have you posted it somewhere? If yes can you help me with the link.
Thanks again for this post!
Cheers!