简体   繁体   English

Azure devops 文物保留

[英]Azure devops artefact retention

I've got a mono repo, which has 10 separate CICD pipelines written in yaml.我有一个 mono repo,它有 10 个独立的 CICD 管道,用 yaml 编写。

I've noticed lately that we've lost a vast number of runs, and some of them had successful production releases.我最近注意到我们已经失去了大量的运行,其中一些已经成功地发布了生产版本。

Am I right in thinking that the project rententiob settings applies to all pipelines?我认为项目rententiob设置适用于所有管道是否正确? Rather than individual?而不是个人?

I've been reading on the ms website and I think in order to retain them going forward, I have to use the API via a powershell script.我一直在阅读 ms 网站,我认为为了让它们继续前进,我必须通过 powershell 脚本使用 API。

I assume the said script needs to run after a successful deployment to production.我假设上述脚本需要在成功部署到生产后运行。

I'm quite surprised that there isn't a global option to say 'keep all production releases'我很惊讶没有一个全局选项可以说“保留所有生产版本”

The project Retention policy settings will be applied to all pipeline runs not individual.项目保留策略设置将应用于所有管道运行而不是单独运行。 So you could not use this setting to retention specific successful production releases directly.因此,您不能使用此设置直接保留特定的成功生产版本。

To achieve this, you could use the PowerShell script to retention these specific runs with "Condition".为此,您可以使用 PowerShell 脚本以“条件”保留这些特定运行。 Add the PowerShell script as the last task of your deployment to check if this one needs to be retained.添加 PowerShell 脚本作为部署的最后一个任务,以检查是否需要保留此脚本。 Refer to this official doc: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/run-retention?view=azure-devops参考这个官方文档: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/run-retention?view=azure-devops

Here is an example to retention forever based on condition:这是一个根据条件永久保留的示例:

- powershell: |
   $contentType = "application/json";
   $headers = @{ Authorization = 'Bearer $(System.AccessToken)' };
   $rawRequest = @{ daysValid = 365000 ; definitionId = $(System.DefinitionId); ownerId = 'User:$(Build.RequestedForId)'; protectPipeline = $false; runId = $(Build.BuildId) };
   $request = ConvertTo-Json @($rawRequest);
   $uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/build/retention/leases?api-version=6.0-preview.1";
   Invoke-RestMethod -uri $uri -method POST -Headers $headers -ContentType $contentType -Body $request;
  displayName: 'PowerShell Script'
  condition: {Your customize condition}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM