问题描述
我有一个Azure DevOps管道,该管道用于旋转某些键.有两个主要要求-
I have an Azure DevOps pipeline that is used to rotate some keys. There are two primary requirements -
- 一次只能旋转一个键.
- 任何键都可以通过手动运行临时旋转.
为此,我计划使用在不同日期运行的cron计划.然后,应使用参数,并根据星期几将默认值设置为特定的键类型".使用参数意味着用户还可以指定手动运行管道时要旋转的键.
To do this, I plan to use a cron schedule that runs on various days. A parameter should then be used with the default being set to a specific 'Key Kind' based on the day of the week. Using a parameter means that a user can also specify the key to rotate when running the pipeline manually.
不幸的是,我想出的办法不起作用.参数中的四个表达式均产生以下错误-
Unfortunately what I've come up with doesn't work. Each of the four expressions in the parameters yeild the following error -
A template expression is not allowed in this context
根据文档 ...
...但是这似乎不正确.我希望我会丢失一些东西,而不是文档不正确,但是无论哪种方式,我都不确定如何实现自己的目标.
...but that does not seem to be correct. I'm hoping that I'm missing something rather than the documentation being incorrect, but either way I'm not sure how I can achieve my goal.
pr: none
trigger: none
schedules:
- cron: 0 2 * * 0-3,6
displayName: Rotate a key
branches:
include:
- develop
always: true
parameters:
- name: keyKinds
displayName: Key Kinds
type: string
${{ if not(in(format('{0:dddd}', pipeline.startTime), 'Sunday', 'Monday', 'Tuesday')) }}:
default: primary
${{ if eq(format('{0:dddd}', pipeline.startTime), 'Sunday') }}:
default: secondary
${{ if eq(format('{0:dddd}', pipeline.startTime), 'Monday') }}:
default: primaryReadonly
${{ if eq(format('{0:dddd}', pipeline.startTime), 'Tuesday') }}:
default: secondaryReadonly
values:
- primary
- secondary
- primaryReadonly
- secondaryReadonly
推荐答案
我认为这可以回答以下问题:
I think that this may answer for the question:
模板表达式可以扩展模板参数以及变量.您可以使用参数来影响模板的扩展方式.参数对象的工作方式类似于表达式中的变量对象.模板表达式中只能使用预定义的变量.
Template expressions can expand template parameters, and also variables. You can use parameters to influence how a template is expanded. The parameters object works like the variables object in an expression. Only predefined variables can be used in template expressions.
仅针对阶段,作业,步骤和容器(内部资源)扩展表达式.例如,您不能在触发器内部使用表达式,也不能在资源库之类的资源中使用表达式.此外,在Azure DevOps 2020 RTW上,您不能在容器内使用模板表达式.
Expressions are only expanded for stages, jobs, steps, and containers (inside resources). You cannot, for example, use an expression inside trigger or a resource like repositories. Additionally, on Azure DevOps 2020 RTW, you can't use template expressions inside containers.
这篇关于如何有条件地设置Azure DevOps参数的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!