Azure DevOps 管道条件 - 为什么包括 "and always"?

Azure DevOps pipeline condition - Why include "and always"?

the documentation for conditions in Azure DevOps pipelines中给出了以下示例:

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

为什么要包含“and(always()”部分?据我了解,它在语义上等同于:

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

还是我遗漏了什么?

此示例的标题为“运行 如果构建已安排,即使失败,即使取消” .

所以,这个条件:

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

用于“运行 如果构建已安排”部分。

而这个条件:

always()

用于“即使失败,即使取消”部分。

这两个由and(...)组成。就是这样。

你说得对,Kristoffer,这两个条件在行为上是等价的。

虽然我会提供一个使用长版本的理由:

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

在编写任务条件时,很容易忘记 succeeded() 是默认值,如果不包含它,即使作业失败或取消,您的任务也会 运行 .

所以我认为在表达式中包含 succeeded()(或 always()cancelled() 或其他)来编写所有条件是一个好习惯;那么如果你看到一个条件 没有它 ,像这样:

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

然后提醒您质疑该条件是否旨在包括 failing/cancelled 个职位。

将其更改为长版本可以消除该错误的风险。