来自自定义工作项内部的参考Wiki页面 [英] Reference Wiki page from inside customized work item
问题描述
我创建了一个自定义的工作项目.可以通过任何方式将此工作项与预先创建的Wiki页面链接.我不想手动将其与工作项链接,而只是在创建新工作项时进行自动链接.
最方便的解决方法是为您的工作项创建一个自定义字段.并创建一个规则,以自动将Wiki页面的url设置为自定义字段的值.
在此处查看教程,以
还有使用azure管道和rest api的另一种解决方法.
请检查以下步骤:
1,创建网络挂钩由创建的工作项
事件
创建Webhook时,您需要提供以下信息:
-
请求网址-
https://dev.azure.com/<ADO Organization>/_ apis/public/distributedtask/webhooks/< WebHook名称>?api-version = 6.0-preview
-
秘密-这是可选的.如果您需要保护JSON有效负载,请提供Secret值
2,创建一个新的传入Webhook".服务连接.
- Webhook名称:Webhook的名称应与您在外部服务中创建的Webhook匹配.
3,创建一个工作项更新其余api.参见以下脚本:
步骤:-powershell:| |$ workitemId = $ {{parameters.MyWebhookTrigger.resource.id}}$ url ="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_ apis/wit/workitems/$($ workitemId)?api-version = 6.1-preview.3"$ body ='[{"op":添加",路径":"/relations/-",值":{"rel":"ArtifactLink","URL":"vstfs:///Wiki/WikiPage/{projectName}/{wikiName}/{wikiPage}",属性":{名称":"Wiki页面";}}}]'Invoke-RestMethod -Uri $ url -Headers @ {Authorization ="Bearer $(system.accesstoken)"} -ContentType"application/json-patch + json"-方法补丁-body $ body
请签出此文档以获取更多信息.
以上步骤实际上是在做以下事情:
已创建新的工作项->自动触发Azure管道-> Azure管道运行脚本以调用rest api将Wiki页面添加到工作项中.
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.
- Webhook Name: The name of the webhook should match webhook created in your external service.
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.
这篇关于来自自定义工作项内部的参考Wiki页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!