简体   繁体   English

Azure DevOps 管道表达式

[英]Azure DevOps Pipelines Expressions

Goal is to condition a task custom extension based on which task is used in pipeline.目标是根据管道中使用的任务来调整任务自定义扩展。 For that we want to use pipelines decorators为此,我们想使用管道装饰器

For example, if any user is using Powershell task in their pipelines, we want to execute our task with decorators.例如,如果任何用户在他们的管道中使用 Powershell 任务,我们希望使用装饰器执行我们的任务。

But we can figure out how to make it works.但我们可以弄清楚如何让它发挥作用。

Yaml: Yaml:

 steps:
 - ${{ if and(eq(resources.repositories['self'].ref, r esources.repositories['self'].defaultBranch), not(containsValue(job.steps.*.task.id, 'd9bafed4-0b18-4f58-968d-86655b4d2ce9'))) }}:
   - script: dir
     displayName: 'Run my script (injected from decorator)'

Directly from Microsoft tutorial直接来自微软教程

Inside Azure DevOps Pipelines, visual editor brings this error:在 Azure DevOps Pipelines 内部,可视化编辑器会出现此错误:

 Unexpected property ${{ if containsValue(job.steps.*.task.id, '1c524b9b-9f4d-4897-8f1e-6ec33271d75c') }}

The first property must be task第一个属性必须是任务

And at runtime:在运行时:

错误

We also tried with condition() :我们还尝试了condition()

condition: |
    and
    (
      eq(dependencies.A.result, 'Succeeded'),
      containsValue(dependencies.A.steps.*.task.id, '1c524b9b-9f4d-4897-8f1e-6ec33271d75c')
    )  

But we can't find correct syntax, object content is null:但是我们找不到正确的语法,object 的内容是 null:

object_null

Anyone know how to retrieve task id and use it to condition any further task?任何人都知道如何检索任务 ID 并使用它来调节任何进一步的任务?

You should put the expression in your Decorator YAML file , not the pipeline azure-pipelines.yml file.您应该将表达式放在装饰器 YAML 文件中,而不是管道 azure-pipelines.yml 文件中。 To get started with Pipeline Decorators, you need to follow the following steps:要开始使用管道装饰器,您需要执行以下步骤:

  • Create an extension file.创建一个扩展文件。 This defines the type of extension, as well as the packaged files.这定义了扩展的类型,以及打包的文件。
  • Create a YAML file.创建 YAML 文件。 This file contains the steps you want to execute for each pipeline.此文件包含您要为每个管道执行的步骤。
  • Create an HTML file.创建 HTML 文件。 This will be displayed when a user views your extension in the Marketplace.这将在用户在 Marketplace 中查看您的扩展程序时显示。
  • Package the extension. Package 扩展。 This creates a.VSIX file you will use to register your extension.这将创建一个 .VSIX 文件,您将使用它来注册您的扩展。
  • Register your extension.注册您的分机。 This involves uploading your file to the Azure DevOps Marketplace and making it available to your Azure DevOps Organization.这包括将您的文件上传到 Azure DevOps Marketplace 并提供给您的 Azure DevOps 组织。
  • Add the extension to your org.将扩展添加到您的组织。 This allows the extension to be applied to your pipelines.这允许将扩展应用到您的管道。

You cam get more details from the following blog:您可以从以下博客获得更多详细信息:

https://soltisweb.com/blog/detail/2019-11-07-simplifying-azure-devops-pipelines-with https://soltisweb.com/blog/detail/2019-11-07-simplifying-azure-devops-pipelines-with

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

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