【问题标题】:How to import/upload multiple json files to Azure Devops Pipeline Release and Builds?如何将多个 json 文件导入/上传到 Azure Devops Pipeline Release and Builds?
【发布时间】:2021-02-08 14:13:34
【问题描述】:

我的桌面上保存了多个 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

【问题讨论】:

    标签: azure azure-devops azure-powershell azure-devops-rest-api


    【解决方案1】:

    如何将多个 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
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-09
      • 2023-03-10
      • 2021-05-14
      • 2021-05-14
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多