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,402 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 03:41 AM
Maybe also post it as blog, not as question? That makes it easier to find when someone is looking for such a solution (I wouldn't look into questions, because I wouldn't expect it there).
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 01:33 AM
Hi,Where to find your next blog on this integration?Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 11:53 AM
By clicking on someone's name, you can see all of their contributions to the community. The next blog hasn't been written/published yet.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 11:59 PM
Hello,
I was advised not to post blogs here never wrote anymore - I will get this content in a more appropriate forum and post the link here