Answers: <p>Yes; you can use the <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&amp;tabs=yaml" rel="nofollow noreferrer">Build.Reason pre-defined variable</a> in a task <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&amp;tabs=yaml" rel="nofollow noreferrer">condition</a>, like this for example:</p>
  <pre><code>condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-12-16T16:25:54.047Z
Answers: 2021-12-16T16:25:54.047Z
Answers: Vince Bowdren
Body: <p>Need to create a YAML based azure build pipeline i.e, need to run particular tasks like only build step when it is PR automated and when the same pipeline  manually run it should run build task along with archive and publish artifact tasks</p>
  
Tags: <azure-devops><azure><azure-pipelines><build-pipeline><yaml>
Title: YAML based azure build pipeline to run particular tasks based on condition?
UserDisplayName: nova world
ThreadText: # YAML based azure build pipeline to run particular tasks based on condition?
  
  (Asked by: username_0 on 2021-08-13)
  
  Need to create a YAML based azure build pipeline i.e, need to run particular tasks like only build step when it is PR automated and when the same pipeline manually run it should run build task along with archive and publish artifact tasks
  
  **Tags:** azure-devops, azure, azure-pipelines, build-pipeline, yaml
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-12-16. Score: 1
  
  Yes; you can use the [Build.Reason pre-defined variable](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml) in a task [condition](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml), like this for example:
  
  ```
  condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
  
  ```
  
  
  ---
  
  