Bal*_*ali 4 azure-devops azure-pipelines azure-devops-rest-api
我正在尝试将密钥作为安全文件上传到 azure devops 以在管道上下文中使用,我只找到了手动上传,但它不是选项,有没有办法可以通过 powershell 或任何管道任务实现自动化?请建议。
您可以使用 REST API 来执行此操作:
POST https://dev.azure.com/{organization}/{project}/_apis/distributedtask/securefiles?api-version=5.0-preview.1&name={fileName}
Content-Type=application/octet-stream
Run Code Online (Sandbox Code Playgroud)
请在 GitHUb 上查看此主题。
你甚至会发现其中有powershell 脚本:
param
(
[Parameter(Mandatory=$true)] [string] $PAT,
[Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()]$AzureDevOpsOrg,
[Parameter(Mandatory=$True)][ValidateNotNullOrEmpty()]$AzureDevOpsProjectID,
[Parameter(Mandatory=$true)] [string] $SecureNameFile2Upload,
[Parameter(Mandatory=$true)] [string] $SecureNameFilePath2Upload
)
try{
$base64AuthInfo=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$PAT)))
$uploadSecureFileURI="https://dev.azure.com/$AzureDevOpsOrg/$AzureDevOpsProjectID/_apis/distributedtask/securefiles?api-version=5.0-preview.1&name=$SecureNameFile2Upload"
$headers = @{
Authorization=("Basic {0}" -f $base64AuthInfo)
}
Invoke-RestMethod -Uri $uploadSecureFileURI -Method Post -ContentType "application/octet-stream" -Headers $headers -InFile "$SecureNameFilePath2Upload"
}
catch
{
write-host -f Red "Error upload client certificate file [$SecureNameFilePath2Upload] to AzureDevOps secure file!" $_.Exception.Message
throw "Error occors -> $_.Exception.Message"
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4093 次 |
最近记录: |