如何有条件地设置Azure DevOps参数的值? [英] How do you conditionally set the value of an Azure DevOps parameter?

查看:65
本文介绍了如何有条件地设置Azure DevOps参数的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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

根据文档 ...

编译时表达式可以在任何地方使用

Compile time expressions can be used anywhere

...但是这似乎不正确.我希望我会丢失一些东西,而不是文档不正确,但是无论哪种方式,我都不确定如何实现自己的目标.

...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:

使用模板表达式指定在管道初始化期间如何动态解析值.将模板表达式用以下语法包装:$ {{}}.

Use template expressions to specify how values are dynamically resolved during pipeline initialization. Wrap your template expression inside this syntax: ${{ }}.

模板表达式可以扩展模板参数以及变量.您可以使用参数来影响模板的扩展方式.参数对象的工作方式类似于表达式中的变量对象.模板表达式中只能使用预定义的变量.

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参数的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆