![](/img/trans.png)
[英]How to import/upload multiple json files to Azure Devops Pipeline Builds?
[英]How to import/upload multiple json files to Azure Devops Pipeline Release and Builds?
我的桌面上保存了多個 Azure DevOps 發布和構建 (.json) 文件。 下面的腳本是添加一個 json 文件。 我正在嘗試將多個構建或發布 json 文件從我的桌面導入 Azure DevOps?
有人可以幫忙嗎?
$token = "PAT token"
$url = "https://dev.azure.com/{organization}/{Project}/_apis/build/definitions?api-version=6.0-preview.2"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON = @'
request body
'@
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
如何將多個 json 文件導入/上傳到 Azure Devops Pipeline Release and Builds?
我們可以使用 powershell 腳本從您的桌面文件夾中解析這些 json 文件的名稱:
$JsonNames = Get-ChildItem C:\Users\<UserName>\Desktop\*.json | Select-Object -ExpandProperty Name
然后我們可以循環這個JsonNames
以導入到 Azure Devops Pipeline Release and Builds:
ForEach ($JN in $JsonNames)
{
$token = "PAT token"
$url = "https://dev.azure.com/{organization}/{Project}/_apis/build/definitions?api-version=6.0-preview.2"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$JSON= Get-Content "C:\Users\<UserName>\Desktop\$($JN).json"
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.