I have created a customized work item. It there any way to link this work item with pre-created wiki page. I don't want to link it with work item manually, just kind of automatic link when create a new work item.
The most convenient workaround is to create a custom field for your work item. And create a rule to automatically set the wiki page url as value of the custom field.
Check tutorial here to Add a custom field.
Check here to Add a rule to a work item type, which will be triggered when a work item is created, and set the wiki url as the custom field value.
There is another workaround using azure pipeline and rest api.
Please check below steps:
1, create web hook to be triggered by Work item created
event
When creating your webhook, you need to provide the following info:
Request Url - https://dev.azure.com/<ADO Organization>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview
Secret - This is optional. If you need to secure your JSON payload, provide the Secret value
2, Create a new "Incoming Webhook" service connection.
3, Create a yaml pipeline.
Add service connection resources in the yaml pipeline see below:
resources:
webhooks:
- webhook: MyWebhookTrigger
connection: MyWebhookConnection #the name of the Incoming Webhook service connection created in above step.
Add script task in your pipeline to call work item update rest api. See below scripts:
steps:
- powershell: |
$workitemId= ${{ parameters.MyWebhookTrigger.resource.id}}
$url = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/wit/workitems/$($workitemId)?api-version=6.1-preview.3"
$body ='
[
{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "ArtifactLink",
"url": "vstfs:///Wiki/WikiPage/{projectName}/{wikiName}/{wikiPage}",
"attributes": {
"name": "Wiki Page"
}
}
}
]'
Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $(system.accesstoken)"} -ContentType "application/json-patch+json" -Method patch -body $body
Please check out this document for more information.
Above steps actually do below things:
New workitem is created-->automatically Trigger Azure pipeline-->Azure pipeline run script to call rest api to add the wiki page to the workitem.