附件的功能及其在工作项跟踪中的用途 API
Functionality of Attachments and their use in Work Item Tracking API
我偶然发现了 documentation for creating attachments, listed under work item tracking, and I'm curious about the functionality. According to 堆栈溢出 post,其功能似乎是将文件上传到“后端”而不与工作项有任何关联。我在理解这个端点的用例是什么时遇到了一些麻烦......它只是一个美化的存储 space 吗?如果没有 UI 查看该项目并且与项目以外的任何现有实体没有关系,它的预期用途是什么?是否有任何我遗漏的可用端点允许我向现有工作项添加附件?
您还需要使用 Work Items - Update rest api 将附件添加到工作项。见下文:
1、首先使用Attachments - Create rest api更新附件到azure devops server。
当附件上传成功后,附件id和url会返回给您。您将需要使用工作项中的附件 url - 更新其余部分 api。参见 examples
2、使用工作项-更新以将附件添加到工作项。将附件 url 放入请求正文中,如下例所示:
[{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
# attachment url
"url": "https://dev.azure.com/fabrikam/_apis/wit/attachments/098a279a-60b9-40a8-868b-b7fd00c0a439?fileName=Spec.txt",
"attributes": {
"comment": "Spec for the work"
}
}
}]
请参阅下面 powershell scipts 中的完整示例:
# Attachments - Create REST API
$url = "https://dev.azure.com/{org}/{proj}/_apis/wit/attachments?fileName=textAsFileAttachment.txt&api-version=6.0"
$PAT="Personal access token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$body= 'this a attached text file'
# update attachment to azure devops server. attachment id and url will be returned
$attachment= Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/octet-stream" -Method post -Body $body
# Work Items - Update REST API
$wurl ="https://dev.azure.com/{org}/{proj}/_apis/wit/workitems/{workitem Id}?api-version=6.0"
$wbody=@(
@{
"op"= "add";
"path"= "/relations/-";
"value"= @{
"rel"= "AttachedFile";
"url"= $attachment.url; #Attachment url
"attributes"= @{
"comment"= "attachment Test"
}
}
})
# add attachment to workitem.
Invoke-RestMethod -Uri $wurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json-patch+json" -Method patch -Body (convertto-json $wbody -Depth 10)
然后您上传到 azure devops 的附件将附加到一个工作项。请参阅上面示例的以下结果:
我偶然发现了 documentation for creating attachments, listed under work item tracking, and I'm curious about the functionality. According to
您还需要使用 Work Items - Update rest api 将附件添加到工作项。见下文:
1、首先使用Attachments - Create rest api更新附件到azure devops server。
当附件上传成功后,附件id和url会返回给您。您将需要使用工作项中的附件 url - 更新其余部分 api。参见 examples
2、使用工作项-更新以将附件添加到工作项。将附件 url 放入请求正文中,如下例所示:
[{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
# attachment url
"url": "https://dev.azure.com/fabrikam/_apis/wit/attachments/098a279a-60b9-40a8-868b-b7fd00c0a439?fileName=Spec.txt",
"attributes": {
"comment": "Spec for the work"
}
}
}]
请参阅下面 powershell scipts 中的完整示例:
# Attachments - Create REST API
$url = "https://dev.azure.com/{org}/{proj}/_apis/wit/attachments?fileName=textAsFileAttachment.txt&api-version=6.0"
$PAT="Personal access token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$body= 'this a attached text file'
# update attachment to azure devops server. attachment id and url will be returned
$attachment= Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/octet-stream" -Method post -Body $body
# Work Items - Update REST API
$wurl ="https://dev.azure.com/{org}/{proj}/_apis/wit/workitems/{workitem Id}?api-version=6.0"
$wbody=@(
@{
"op"= "add";
"path"= "/relations/-";
"value"= @{
"rel"= "AttachedFile";
"url"= $attachment.url; #Attachment url
"attributes"= @{
"comment"= "attachment Test"
}
}
})
# add attachment to workitem.
Invoke-RestMethod -Uri $wurl -Headers @{Authorization = "Basic {0}" -f $base64AuthInfo} -ContentType "application/json-patch+json" -Method patch -Body (convertto-json $wbody -Depth 10)
然后您上传到 azure devops 的附件将附加到一个工作项。请参阅上面示例的以下结果: