If you’re using Azure DevOps in yor organization for the entire product lifecycle, you know for sure that you can handle also all your project management activities by using work items, boards, backlogs, sprints and so on. I’ve talked about that in the past here.
What personally we use a lot internally is the Work Items feature. By using work items you can track anything, from a task to do, a feature to implement, an impediment, an epic and a bug. You can open work items inside a project and assign those items to your team members easily:
The interesting part is that you can also commit code linked to a work item or to a bug for a complete tracking directly from Visual Studio Code or Visual Studio.
I think that when you start using those features widely, the first thing that comes to your mind is: can I automate the creation of a task or a bug, or in general any work item? This can be useful expecially if you want to permit to external users to open bugs for example.
Azure DevOps offers a set of REST APIs for automating the creation of things and for reading data from external applications. You can see the available APIs here.
We’ve automated the creation of tasks and bugs (or more in general, the creation of work items) by using an external application. Here I want to share a solution for doing this that uses a simple Powershell script.
To access the Azure DevOps REST APIs you need to be authenticated and so you need to create a Personal Access Token for your organization (top right corner, click on the user icon and select Personal access tokens).
For authentication, you need to send a Basic authentication header with the access token you have created to the url of your organization (https://dev.azure.com/OrganizationName).
To create a work item, you need to send a POST request to the workitems API by passing a JSON body that defines your work item (JSON array). More details can be found here. The script to create a work item with the type you want is as follows:
When executed, this is the output in Powershell:
and these are my tasks and bugs created from Powershell in Azure DevOps:
You can find the script here. Quite interesting if you want to automate work items creation from external events isn’t it?
And what about if you want to create a system for opening tasks and bugs (or other work items) directly from Dynamics 365 Business Central? You can create an extension that permits you to insert a work item and then calls the Azure DevOps REST API.
As an example, I’ve created an extension with a table that stores my opened work items in Dynamics 365 Business Central as follows:
Then I’ve created a list page as a UI for opening a work item. On this page I have an action that takes all the work items not sent to Azure DevOps and then sends them to Azure DevOps by calling its REST API. Code for the page is omitted here (very easy to do):
The business logic for calling the Azure DevOps REST API is defined in a codeunit as follows:
What happens here? For each work item inserted into Dynamics 365 Business Central, a JSON representation is created, the REST API is called and the work item is created into the selected Azure DevOps project:
This sample can obviously be improved. For example you should parse the API response (JSON) in order to retrieve the Azure DevOps ID for the work item and store this ID into the Dynamics 365 Business Central table for traceability and so on but I think you’ve learned now that you can automate your DevOps processes also from scripts or directly from your ERP.
how do I pass an attachment on PowerShell to be attached on wI
Not sure if the API permits you to do that. I need to check the documentation.
Thank you! I see it.
Awesome work man you saved my day! thanks a ton.
Could you please help me how do I assigned newly created work item to a user via your powershell script.
Awesome informative you saved my day! thanks a ton man!.
Could you please help me with how to assign newly created task to a user using your powershell script..?
any help will be appreciate.
Nice Work! What about downloading an attachment from DevOps with PowerShell?