繁体   English   中英

Azure DevOps Pipeline - 我可以根据一天中的时间运行不同的任务吗?

[英]Azure DevOps Pipeline - Can I run different tasks based on time of day?

我的仓库中有两个 python 文件。 使用 azure 管道,我希望 file1 在一天中的一个特定小时运行,并且我希望 file2 在其余时间的顶部运行。

我目前在 azure_pipeline.yml 文件中定义了一项作业,其中一项任务正在运行 file1。 如何根据上述条件调整作业或任务以运行任一文件?

如何根据上述条件调整作业或任务以运行任一文件?

您可以使用计划触发器和system.pipelinestarttime变量来设置条件或 if 表达式。

system.pipelinestarttime 变量的格式: 2022-06-30 03:13:20+00:00

这是一个例子:

schedules:
- cron: "   1 * * * *"
  displayName: Daily midnight build
  branches:
    include:
    - main
  always: true

pool:
  vmImage: ubuntu-latest

steps:
- ${{ if and(eq(variables['Build.Reason'], 'Schedule'), contains(variables['system.pipelinestarttime'], 'time for example: 3:14')) }}:
  - task: file 1

- ${{ else }}:
  - task: file 2

有关更多详细信息,您可以参考此文档: Scheduled triggers and Expressions

更新:

您可以使用两个单独的管道来使用这些文件。

这是一个例子:

YAML 1:

schedules:
- cron: "   * 1 * * *"
  displayName: specific hour
  branches:
    include:
    - main
  always: true

pool:
  vmImage: ubuntu-latest

steps:
  - task: file 1

YAML 2

schedules:
- cron: "   1 * * * *"
  displayName: Other hours
  branches:
    include:
    - main
  always: true

pool:
  vmImage: ubuntu-latest

steps:
  - task: file 2

创建管道时,您可以选择 YAML 文件来创建管道。

在此处输入图像描述

根据我的评论,您可以使用其他 cron 设置创建第二个管道,这非常简单:

您可以在一个存储库中创建任意数量的 Devops 构建管道。

如果你抛出创建 Buid Pipeline 的正常步骤,Azure Devops 将创建一个新的 azure-pipelines-*.yml 文件(第一个文件名为 azure-pipelines.yml)

新管道

默认文件名是 azure-pipelines.yml,但如果您愿意,也可以稍后重命名该文件:

项目设置

暂无
暂无

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

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