如何配置O365PostMessageBuild任务使其仅在计划触发流水线时执行?
Got it! To ensure your O365PostMessageBuild@0 task executes only when the pipeline is triggered by your scheduled cron job, you'll need to adjust the task's condition to check against Azure DevOps' built-in pipeline variable.
Step-by-Step Adjustment
Azure DevOps sets the Build.Reason predefined variable based on how the pipeline was triggered. For scheduled runs, this variable's value is Schedule.
You'll want to combine this check with your existing succeededOrFailed() condition (so the notification sends whether the run passed or failed, but only for scheduled triggers). Here's the updated task configuration:
- task: O365PostMessageBuild@0 condition: and(succeededOrFailed(), eq(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'
Why This Works
eq(variables['Build.Reason'], 'Schedule')ensures the task only runs when the pipeline is triggered by your cron schedule (like your daily midnight build on themainbranch).- Keeping
succeededOrFailed()means the notification will still send regardless of whether the pipeline run succeeded or failed—just like your original setup, but restricted to scheduled triggers.
This change won't affect any other pipeline triggers (like manual runs, PR builds, or CI triggers on code pushes)—the notification task will skip those entirely.
内容的提问来源于stack exchange,提问作者FarFarAway

