0
votes

I have multiple Azure DevOps release and build (.json) files saved on my desktop. The script below is to add one json file. I am trying to import multiple build or release json files from my desktop to Azure DevOps?

Can someone please help?

$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

1

1 Answers

0
votes

How to import/upload multiple json files to Azure Devops Pipeline Release and Builds?

We could use powershell scripts to parse the names of these json files from your desktop folder:

$JsonNames = Get-ChildItem C:\Users\<UserName>\Desktop\*.json | Select-Object -ExpandProperty Name

Then we could loop this JsonNames to import to 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


}