【问题标题】:Trigger O365PostMessageBuild only when the pipeline is runned by schedule仅当管道按计划运行时触发 O365PostMessageBuild
【发布时间】:2021-08-30 10:19:55
【问题描述】:

我有以下时间表在准备中

schedules:
  - cron: "0 0 * * *"
    displayName: Daily midnight build
    branches:
      include:
        - main

我用它来发送通知

  - task: O365PostMessageBuild@0
    condition: succeededOrFailed()
    inputs:
      addressType: 'url'
      url: 'https://webhook.office.com/webhookb2/9615602a-d293-4469-ba56'
      messageType: 'message'
      title: 'Test Result'
      summary: 'Scheduled nightly test run'
      text: 'Branch : main'
      includeLink: true
      linkText: 'View last run'

我希望仅在触发管道时执行任务。我怎样才能做到这一点。

【问题讨论】:

  • 你的意思不是 cron?

标签: azure azure-devops azure-pipelines


【解决方案1】:

如果您想为 cron 以外的其他触发器安排任务,您需要为任务添加条件:

  - task: O365PostMessageBuild@0
    condition: and(succeededOrFailed(), (variables['Build.Reason'], 'Schedule'))
    inputs:
      addressType: 'url'
      url: 'https://webhook.office.com/webhookb2/9615602a-d293-4469-ba56'
      messageType: 'message'
      title: 'Test Result'
      summary: 'Scheduled nightly test run'
      text: 'Branch : main'
      includeLink: true
      linkText: 'View last run'

Here 你有所有可能值的列表:

导致构建运行的事件。

Manual: A user manually queued the build.
IndividualCI: Continuous integration (CI) triggered by a Git push or a TFVC check-in.
BatchedCI: Continuous integration (CI) triggered by a Git push or a TFVC check-in, and the Batch changes was selected.
Schedule: Scheduled trigger.
ValidateShelveset: A user manually queued the build of a specific TFVC shelveset.
CheckInShelveset: Gated check-in trigger.
PullRequest: The build was triggered by a Git branch policy that requires a build.
ResourceTrigger: The build was triggered by a resource trigger or it was triggered by another build.

【讨论】:

    【解决方案2】:

    我希望仅在触发管道时执行任务。我怎样才能做到这一点。

    您似乎希望仅在源代码发生更改时才执行任务,这会触发管道。

    要实现这一点,您可以将参数 always: boolean 添加到此任务:

    schedules:
    - cron: string # cron syntax defining a schedule
      displayName: string # friendly name given to a specific schedule
      branches:
        include: [ string ] # which branches the schedule applies to
        exclude: [ string ] # which branches to exclude from the schedule
      always: boolean # whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run. The default is false.
    

    更多详情请查看文档Scheduled triggers

    【讨论】:

      猜你喜欢
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 2021-09-17
      • 2023-03-14
      • 2018-04-12
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多