简体   繁体   English

如何阻止 azure-devops 发布管道失败

[英]How to stop azure-devops release-pipeline from failing

I have a release-pipeline that deploys builds.我有一个部署构建的发布管道。 It's set to run after the build finishes.它设置为在构建完成后运行。 Builds have a BuildNumber that includes the product version number.构建具有包含产品版本号的 BuildNumber。 I want to only deploy zero builds that have a version number ending with .0我只想部署版本号以 .0 结尾的零构建

I tried adding a Stage with a Powershell task that checks the version number and fails if it's not a zero build.我尝试添加一个带有 Powershell 任务的 Stage,该任务检查版本号,如果它不是零构建则失败。 I also tried to add a gate to the deployment stage that also checks the version number.我还尝试在部署阶段添加一个检查版本号的门。

Both of these ways of checking result in the release-pipeline failing, and I get an email telling me it's failed.这两种检查方式都会导致发布管道失败,我收到一封电子邮件,告诉我它失败了。

How can I make the release-pipeline succeed, but do nothing for non-zero builds?如何使发布管道成功,但对非零构建不执行任何操作?

The powershell was:电源外壳是:

if ( "$(Release.Artifacts._TheBuild.BuildNumber)" -like ".0 " )
{
    exit 0
}
else
{
    exit 1
}

The gate calls out to an azure function and passes $(Release.Artifacts._TheBuild.BuildNumber) as an argument.门调用 azure 函数并将 $(Release.Artifacts._TheBuild.BuildNumber) 作为参数传递。 The azure function returns json with a status of true or false depending on whether the version number ends with zero. azure 函数返回状态为真或假的 json,具体取决于版本号是否以零结尾。 The gate evaluates this immediately, has the minimum retry and timeout of 5 and 6 minutes respectively.门立即对此进行评估,最小重试和超时分别为 5 分钟和 6 分钟。

This can be done via Custom Condition under the control option (For every task this will be available).这可以通过control option下的Custom Condition来完成(对于每个任务,这都可用)。

You can achieve this by defining a specific conditions to run the specific task.您可以通过定义特定条件来运行特定任务来实现这一点。

In your case, you want to run the task when your version no is 0 .在您的情况下,您希望在版本号为0时运行该任务。 So you just define the custom conditions in the control Options to speific the codntion like所以你只需在control Options定义custom conditions来指定像

and(succeeded(), eq(variables['Release.Artifacts._TheBuild.BuildNumber'], '0'))

在此处输入图片说明

So this task will execute only when the condtion satisify else the task will skip it's exectuion.所以这个任务只有在条件满足时才会执行,否则任务将跳过它的执行。

If I understood correctly, you only want to deploy builds that have a version number that ends with .0如果我理解正确,您只想部署版本号以.0结尾的版本

You can try adding a release pipeline Continuous Deployment Trigger and add a branch filter that only searches for the version number via a tag .您可以尝试添加发布管道持续部署触发器并添加仅通过标签搜索版本号的分支过滤器

To do this, first go to the release you want to change, click on the ... ellipsis next to the release name, and click Edit.为此,首先转到要更改的版本,单击版本名称旁边的 ... 省略号,然后单击编辑。

This should bring you to the release's pipeline view.这应该会将您带到发布的管道视图。 Once here, click on the little lighting bolt icon to open the Continuous Deployment Trigger editor:在这里,单击小闪电图标以打开持续部署触发器编辑器:

Azure DevOps - 在发布管道上编辑持续部署触发器

This should open the editor on the right hand side.这应该会打开右侧的编辑器。 Here you'll see a place to edit Build branch filters.在这里你会看到一个编辑构建分支过滤器的地方。 Click on the + Add button to add one.单击 + 添加按钮添加一个。

A new row will popup for you to configure your filter.将弹出一个新行供您配置过滤器。 It's here where I believe you can filter for your version number via build tag.在这里,我相信您可以通过构建标记过滤您的版本号。

Azure DevOps - 将构建分支过滤器添加到连续部署触发器

Obviously, you will have to edit your build pipeline as well to add this tag so that you can filter for it here in the release.显然,您还必须编辑您的构建管道以添加此标签,以便您可以在发布中的此处对其进行过滤。

You would add this tag in the Build tags input.您将在构建标签输入中添加此标签。

暂无
暂无

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

相关问题 Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? 使用 powershell,如何使用 api 重新运行在 azure-devops 中失败的版本? - Using powershell, how can i re-run a release which has failed in azure-devops using an api? 如何通过 Azure DevOps 发布管道中的 Azure Powershell 更新暂存槽的 IP 白名单? - How do I update the IP whitelist for a staging slot via Azure Powershell from an Azure DevOps Release Pipeline? 如何在 Azure Devops 发布管道中使用 PowerShell 设置环境变量? - How to set an environment variable with PowerShell in Azure Devops release pipeline? 从 Azure DevOps Release Pipeline 调用控制台应用程序 - Calling console application from Azure DevOps Release Pipeline Azure Devops发布管道中的参数块问题 - Problems with param block in a Azure Devops release pipeline Azure Devops powershell 发布管道奇怪的字符 - Azure Devops powershell release pipeline strange chars 托管代理失败的 Azure DevOps 构建管道 - Azure DevOps build pipeline with hosted agent failing 如何从Azure DevOps管道向Azure密钥库写入机密? - How to write a secret to azure key vault from Azure DevOps pipeline? 如何通过 azure devops 发布管道中的 powershell 任务创建 azure 资源? - How to create a azure resource through powershell task in azure devops release pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM