gpt4 book ai didi

azure-devops - 如何在 Azure DevOps 中自动将工件提升到源 View ?

转载 作者:行者123 更新时间:2023-12-03 23:13:41 24 4
gpt4 key购买 nike

我们的构建工件是一个 Octopus nuget 包。当构建发布时,它会进入 QA 阶段,在该阶段通过 Octopus 部署工件。这只 Octopus 直接从 Azure Artifacts nuget 提要中使用它。

如果部署和后续测试成功,我们希望将工件提升到 Azure Artifacts nuget 提要的发布 View ,因为我们认为它为我们提供了一个不同的 nuget URL,可供下一个阶段的另一个 Octopus 使用(对于历史我们在每个阶段都使用 Octopus 的原因 - 努力改变这一点,但这需要时间)。

我们可以手动推广,但我们希望自动进行。如何才能做到这一点?

我们正在本地 TFS 2019 RC2 上对其进行测试。

enter image description here

编辑 1

建议的插件似乎没有安装在本地 TFS 2019 RC2 上:

enter image description here

最佳答案

使用 PowerShell...

$organisationName = '' # Name of organisation
$projectName = '' # Name of project
$feedName = '' # Name of Azure Artifacts feed
$viewName = 'Release' # I believe this can also be Prerelease, but I've not tried it

# List of names of packages within Azure Artifacts feed to be promoted
$packagesToPromote = @('')

# Need a personal access token for this script to work
# PAT token should be assigned to Packaging (Read, Write and Manage) scopes
$azureArtifactsPAT = ''
$AzureArtifactsPAT_Base64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($azureArtifactsPAT)"))
$restAPICallHeader = @{ Authorization = "Basic $AzureArtifactsPAT_Base64" }

$feedBaseURL = "https://feeds.dev.azure.com/$organisationName/$projectName/_apis/packaging/feeds"
$packageBaseURL = "https://pkgs.dev.azure.com/$organisationName/$projectName/_apis/packaging/feeds"

$feedIdURL = "$feedBaseURL/$feedName/?api-version=5.1-preview.1"
$feedIdResponse = (Invoke-RestMethod -Method Get -Uri $feedIdUrl -Headers $restAPICallHeader -ContentType 'application/json')
$feedId = $feedIdResponse.id

$viewIdURL = "$feedBaseURL/$feedId/views/$viewName/?api-version=5.1-preview.1"
$viewIdResponse = (Invoke-RestMethod -Method Get -Uri $viewIdUrl -Headers $restAPICallHeader -ContentType 'application/json')
$viewId = $viewIdResponse.id


$restAPICallBodyJson = @{
views = @{
op = 'add'
path = '/views/-'
value = "$viewId"
}
}
$restAPICallBody = (ConvertTo-Json $restAPICallBodyJson)

foreach ($packageName in $packagesToPromote) {

$packageQueryUrl = "$feedBaseURL/$feedId/packages?api-version=5.1-preview.1&packageNameQuery=$packageName"
$packagesResponse = (Invoke-RestMethod -Method Get -Uri $packageQueryUrl -Headers $restAPICallHeader -ContentType 'application/json')
$latestPackageVersion = ($packagesResponse.value.versions | ? { $_.isLatest -eq $True } | Select -ExpandProperty version)
$encodedPackageVersion = [System.Web.HttpUtility]::UrlEncode($latestPackageVersion)

Write-Host "Package Name: $packageName"
Write-Host "Package Version: $latestPackageVersion"

$releaseViewURL = $packageBaseURL `
+ "/$($feedId)" `
+ "/nuget/packages/$packageName" `
+ "/versions/$encodedPackageVersion" `
+ "?api-version=5.1-preview.1"

$response = Invoke-RestMethod -Method Patch -Uri $releaseViewURL -Headers $restAPICallHeader -ContentType 'application/json' -Body $restAPICallBody
Write-Host $response
}
作为引用,上面的脚本使用了以下 API 调用:
饲料管理 - 获取饲料
https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/get%20feed?view=azure-devops-rest-5.1
订阅源管理 - 获取订阅源 View
https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/feed%20%20management/get%20feed%20view?view=azure-devops-rest-5.1
神器详细信息 - 获取包
https://docs.microsoft.com/en-us/rest/api/azure/devops/artifacts/artifact%20%20details/get%20packages?view=azure-devops-rest-5.1
NuGet - 更新包版本
https://docs.microsoft.com/en-us/rest/api/azure/devops/artifactspackagetypes/nuget/update%20package%20version?view=azure-devops-rest-5.1

关于azure-devops - 如何在 Azure DevOps 中自动将工件提升到源 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com