如何 import/upload 多个 json 文件到 Azure Devops Pipeline Releases?

How to import/upload multiple json files to Azure Devops Pipeline Releases?

以下脚本尝试将多个 json 文件导入 Azure DevOps Pipeline Release。

$JsonNames = Get-ChildItem C:\Users\path\Downloads\*.json | Select-Object -ExpandProperty Name

ForEach ($JN in $JsonNames)

{

$token = "PAT"

$url = "https://vsrm.dev.azure.com/{organizationName}/{ProjectName}/_apis/release/definitions?api-version=6.0"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON= Get-Content "C:\Users\<UserName>\Desktop$($JN).json"

echo $JSON


$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON


}

我收到以下错误消息。我已经使用 Get Rest API 来获取新的发布定义,更新了项目和构建 ID,但仍然收到此错误消息。有没有办法让脚本忽略工件 ID?

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"VS402962: No artifact version ID is specified corresponding to artifact source 'Test'. Specify 
a valid value and try again.","typeName":"Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.InvalidRequestException, 
Microsoft.VisualStudio.Services.ReleaseManagement2.Data","typeKey":"InvalidRequestException","errorCode":0,"eventId":3000}
At line:19 char:13
+ $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "B ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

根据我的测试,当您尝试将 json 文件上传到发布管道时,您只需要更改 queueid 并发布 定义 ID.

例如:修改release定义名前的queueId和release id

"downloadInputs":[]},"queueId":227,"demands":

"IntegrateJiraWorkItems":{"$type":"System.String","$value":"false"}},"id":10,"name":"New release pipeline (511)","path":"\"

虽然你必须在不同的项目中上传发布定义json,你仍然不需要更改buildidprojectid.

然后相同的脚本将成功创建发布。

VS402962: No artifact version ID is specified corresponding to artifact source 'Test'. Specify a valid value and try again

根据错误消息,您可以检查原始发布管道中构建工件的版本。您需要确保工件的版本存在。