简体   繁体   English

Azure DevOps 管道条件 - 为什么包括“并且始终”?

[英]Azure DevOps pipeline condition - Why include "and always"?

In the documentation for conditions in Azure DevOps pipelines the following example is given:Azure DevOps 管道中的条件文档中,给出了以下示例:

and(always(), eq(variables['Build.Reason'], 'Schedule'))

Why would you include the "and(always()" part? To my understanding it is semantically equivalent to just:为什么要包含“and(always()”部分?据我了解,它在语义上等同于:

 eq(variables['Build.Reason'], 'Schedule')

Or am I missing something?还是我错过了什么?

This example is titled as " Run if the build is scheduled, even if failing, even if canceled ".这个例子的标题是“运行如果构建被安排,即使失败,即使被取消”。

So, this condition:所以,这个条件:

eq(variables['Build.Reason'], 'Schedule')

is for " Run if the build is scheduled " part.用于“如果计划构建则运行”部分。

And this condition:而这个条件:

always()

is for " even if failing, even if canceled " part.用于“即使失败,即使取消”部分。

Those two are composed with and(...) .这两个由and(...)组成。 That's it.而已。

You're right Kristoffer, the two conditions are behaviourally equivalent.你是对的 Kristoffer,这两个条件在行为上是等效的。

I would offer one reason to use the long version though:不过,我会提供一个使用长版本的理由:

and(always(), eq(variables['Build.Reason'], 'Schedule'))

When writing task conditions, it is easy to forget that succeeded() is the default, and if you don't include it then your task will run even if the job is failing or cancelled.在编写任务条件时,很容易忘记succeeded()是默认值,如果你不包含它,那么即使作业失败或取消,你的任务也会运行。

So I think it would be a good practice to write all conditions with succeeded() (or always() or cancelled() or whatever) included in the expression;所以我认为在表达式中包含succeeded() (或always()cancelled()或其他)编写所有条件是一个好习惯; then if you see a condition without it , like this:然后,如果您看到没有它的情况,如下所示:

eq(variables['Build.Reason'], 'Schedule')

then you are reminded to question whether the condition was intended to include failing/cancelled jobs or not.然后提醒您质疑该条件是否旨在包括失败/取消的工作。

Changing it to the long version takes away the risk of that mistake.将其更改为长版本可以消除该错误的风险。

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

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