简体   繁体   中英

How to track what triggered my pipeline on Azure DevOps?

I am using YML file to configure my azure pipelines. My pipeline can either be triggered by new commits to development branch and/or scheduled cron. How can I track which triggered the pipeline? I wanted to do some task based on what triggered by pipeline, whether from a new commit or a cron. It's a small add-on task, so I am avoiding writing a new pipeline to separate the tasks. Thanks in advance!

Here is my code sample:

trigger:
  - development

schedules:
  - cron: '0 0 * * *' # will run midnight every day
    displayName: 'Midnight tests' (UTC - 7:00)'
    branches:
          include:
            - development
        always: true

stages:
### do some work

We could add task bash and enter script printenv to print all pipeline env variable. Then we could see the variable BUILD_REASON , we can track this variable to check how the build pipeline is triggered.

Schedule is trigger from cron, IndividualCI is trigger from commit push. You could check the pic below.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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