1

我正在使用 Azure DevOps rest api 在 Releases 中创建文件夹。不确定,如何在同一路径中创建多个文件夹、子文件夹?

代码 :

'

Param( 
[string]$organisation = "org", 
[string]$project = "testdatafactory", 
[string]$keepForever = "true", 
[string]$user = "id", 
[string]$token = "token",
[string]$path= "\\") 

$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($token)")) }

$uri = "https://vsrm.dev.azure.com/$organisation/$project/_apis/release/folders/$path ?api-version=6.0-preview"


Write-Host "Uri :" $uri

$params = 
@"
{
    "createdBy": "id",
    "createdOn": "",
   "description": "test",
   "lastChangedBy": "",
   "lastChangedDate": "",
   "path": "test1"
    }
"@


$result = Invoke-RestMethod -Uri $uri -Method POST -Body $params -Headers $headers -ContentType "application/json" -Verbose -Debug

'

4

1 回答 1

1

如何在同一路径中创建多个文件夹、子文件夹?

恐怕没有这种开箱即用的方式来创建多个文件夹,同一路径中的子文件夹。

那是因为Folders - Create没有这样的 Batch REST API 。

作为解决方法,我们可以多次运行 REST API 来创建多个文件夹、子文件夹。

我们可以使用 REST API:

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/folders?api-version=6.0-preview.2

然后在请求正文中指定完整路径:

{
    "path": "\\Master\\test5",
    "createdBy": "id"
}

测试结果:

在此处输入图像描述

在此处输入图像描述

如果我们想在同一路径中创建子文件夹,我们可以指定路径,如"path": "\\Master\\test5\\subfolder1"::

在此处输入图像描述

于 2021-05-25T08:04:40.537 回答