Skip to content

Commit 437de04

Browse files
committed
changes
1 parent 8c7048a commit 437de04

File tree

1 file changed

+61
-65
lines changed

1 file changed

+61
-65
lines changed

docs/pipelines/process/conditions.md

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Pipeline conditions
33
description: Learn about conditions that Azure Pipelines stages, jobs, or steps can run under, and ways to specify those conditions.
44
ms.topic: conceptual
55
ms.assetid: C79149CC-6E0D-4A39-B8D1-EB36C8D3AB89
6-
ms.date: 07/29/2025
6+
ms.date: 07/31/2025
77
monikerRange: '<= azure-devops'
88
#customer intent: As an Azure Pipelines user, I want to understand the conditions that pipeline stages, jobs, and steps can run under, so I can configure builds to run under various conditions.
99
---
@@ -23,7 +23,7 @@ By default, a pipeline job or stage runs if it doesn't depend on any other job o
2323

2424
By default, a step runs if nothing in its job failed yet and the step immediately preceding it completed. For more context on stages, jobs, and steps, see [Key concepts for Azure Pipelines](../get-started/key-pipelines-concepts.md).
2525

26-
You can override or customize these default behaviors by setting a stage, job, or step to run even if or only if a previous dependency fails or has another outcome, or by defining [custom conditions](#custom-conditions). In a YAML pipeline definition, you use the `condition` property to specify conditions under which a stage, job, or step can run.
26+
You can override or customize these default behaviors by setting a stage, job, or step to run even if or only if a previous dependency fails or has another outcome. You can also define [custom conditions](#custom-conditions). In a YAML pipeline definition, you use the `condition` property to specify conditions under which a stage, job, or step can run.
2727

2828
[!INCLUDE [include](includes/task-run-built-in-conditions.md)]
2929

@@ -45,7 +45,7 @@ jobs:
4545
- script: |
4646
echo "This task will fail."
4747
exit job1
48-
- job: 2
48+
- job: job2
4949
dependsOn: job1
5050
condition: failed() # this job runs only if job1 fails
5151
```
@@ -57,11 +57,11 @@ If the built-in conditions don't meet your needs, you can specify custom conditi
5757
The agent evaluates the expression beginning with the innermost function and proceeding outward. The final result is a boolean value that determines whether or not to run the stage, job, or step. For a full guide to the syntax, see [Expressions](expressions.md).
5858
5959
> [!IMPORTANT]
60-
> Conditions are evaluated to determine whether to start a stage, job, or step. Therefore, nothing that's computed at runtime inside a stage, job, or step is available to use within that same stage, job, or step. For example, if you set a variable using a runtime expression with `$[ ]` syntax in a job, you can't use that variable in conditions within that job.
60+
> Conditions are evaluated to determine whether to start a stage, job, or step. Therefore, nothing computed during the runtime of a stage, job, or step is available to use within that same stage, job, or step. For example, if you set a variable in a job using a runtime expression with `$[ ]` syntax, you can't use that variable in conditions within that job.
6161

6262
## Variables in conditions
6363

64-
You can set variables and use them in conditions. The following pipeline sets an `isMain` variable and uses it in a condition that runs Stage B only when the build source branch is `main`.
64+
You can set pipeline variables and use them in conditions. The following pipeline sets an `isMain` variable and uses it in a condition that runs Stage B only when the build source branch is `main`.
6565

6666
```yaml
6767
variables:
@@ -96,9 +96,9 @@ jobs:
9696
condition: eq(variables.testEmpty, '')
9797
```
9898

99-
### Job output variables used in subsequent job conditions
99+
### Job output variables used in other job conditions
100100

101-
You can make variables available for future jobs in the same stage to specify in conditions. Variables available to future jobs must be marked as [multi-job output variables](variables.md#set-a-multi-job-output-variable) by using `isOutput=true`, as in the following code:
101+
You can create a variable in a job that other jobs in the same stage can specify in conditions. Variables available to dependent jobs must be marked as [multi-job output variables](variables.md#set-a-multi-job-output-variable) by using `isOutput=true`, as in the following code:
102102

103103
```yaml
104104
jobs:
@@ -117,7 +117,7 @@ jobs:
117117

118118
### Step variables used in subsequent step conditions
119119

120-
You can create a variable in a step that future steps in the same job can specify in a condition. Variables created from steps are available to future steps by default and don't need to be marked as multi-job output variables.
120+
You can create a variable in a step that future steps in the same job can specify in conditions. Variables created from steps are available to future steps in the job by default and don't need to be marked as multi-job output variables.
121121

122122
Variables created in a step in a job have the following limitations:
123123

@@ -143,60 +143,6 @@ steps:
143143
condition: and(succeeded(), eq(variables['doThing'], 'Yes')) # or and(succeeded(), eq(variables.doThing, 'Yes'))
144144
```
145145

146-
## Parameters in conditions
147-
148-
Parameter expansion occurs before conditions are evaluated. Therefore, when you declare a parameter in a pipeline, you can embed the parameter inside any conditions in that pipeline. The script step in the following example runs because the preceding step succeeded and `parameters.doThing` is `true`.
149-
150-
```yaml
151-
parameters:
152-
- name: doThing
153-
default: true
154-
type: boolean
155-
156-
steps:
157-
- script: echo I did a thing
158-
condition: and(succeeded(), ${{ eq(parameters.doThing, true) }})
159-
```
160-
161-
The `condition` in the preceding pipeline combines two functions: `succeeded()` and `${{ eq(parameters.doThing, true) }}`. The `succeeded()` function checks if the previous step succeeded. This function also returns `true` if there was no previous step.
162-
163-
The `${{ eq(parameters.doThing, true) }}` function checks whether the `doThing` parameter is equal to `true`. Since the pipeline sets the default value for `doThing` as `true`, the condition returns `true` unless the pipeline sets a different value.
164-
165-
### Template parameters in conditions
166-
167-
When you pass a parameter to a template, you can set the parameter's value in the template or [use templateContext to pass the parameter to the template](template-parameters.md?view=azure-devops&preserve-view=true#use-templatecontext-to-pass-properties-to-templates).
168-
169-
The following *parameters.yml* template file declares the `doThing` parameter with a default value of `true`.
170-
171-
```yaml
172-
# parameters.yml
173-
parameters:
174-
- name: doThing
175-
default: true
176-
type: boolean
177-
178-
jobs:
179-
- job: B
180-
steps:
181-
- script: echo I did a thing
182-
condition: ${{ eq(parameters.doThing, true) }}
183-
```
184-
185-
The following *azure-pipelines.yml* pipeline definition references the job in the *parameters.yml* template file. The output of the pipeline is `I did a thing` because the parameter `doThing` is true.
186-
187-
```yaml
188-
# azure-pipelines.yml
189-
parameters:
190-
- name: doThing
191-
default: true
192-
type: boolean
193-
194-
extends:
195-
template: parameters.yml
196-
```
197-
198-
For more template parameter examples, see the [Template usage reference](templates.md).
199-
200146
## Condition settings for various outcomes
201147

202148
The following table shows `condition` settings to produce various desired outcomes.
@@ -208,7 +154,7 @@ The following table shows `condition` settings to produce various desired outcom
208154
| Run if the source branch isn't `main`, and the parent or preceding stage, job, or step succeeded. | `and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))` |
209155
| Run for `user` branches if the parent or preceding stage, job, or step succeeded. | `and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/users/'))` |
210156
| Run for continuous integration (CI) builds, if the parent or preceding stage, job, or step succeeded. | `and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI'))` |
211-
| Run if the build was triggered by a pull request and the parent or preceding stage, job, or step failed. | `and(failed(), eq(variables['Build.Reason'], 'PullRequest'))` |
157+
| Run if a pull request triggered the build and the parent or preceding stage, job, or step failed. | `and(failed(), eq(variables['Build.Reason'], 'PullRequest'))` |
212158
| Run for a scheduled build, even if the parent or preceding stage, job, or step failed or was canceled. | `eq(variables['Build.Reason'], 'Schedule')` |
213159
| Run if the `System.debug` variable is set to `true`, even if the parent or preceding stage, job, or step failed or was canceled. | `eq(variables['System.debug'], true)` |
214160

@@ -221,7 +167,7 @@ Canceling a build doesn't mean that all its stages, jobs, and steps stop running
221167

222168
A stage, job, or step runs whenever its conditions evaluate to `true`. If a condition doesn't account for the state of the task's parent, the task might run even if its parent is canceled. To control whether jobs, stages, or steps run when a build is canceled, include a [job status check function](expressions.md?view=azure-devops&preserve-view=true#job-status-functions) in your conditions.
223169

224-
If you cancel a build while it's in the queue stage but not yet running, the entire job is canceled, including all other stages.
170+
If you cancel a build while it's in the queue stage but not yet running, the entire run is canceled, including all other stages.
225171

226172
>[!NOTE]
227173
>If any of your conditions make it possible for tasks to run even after the build is canceled, specify a value for [cancel timeout](phases.md#timeouts) that provides enough time for the tasks to complete after the run is canceled.
@@ -349,6 +295,56 @@ steps:
349295
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
350296
```
351297

298+
## Parameters in conditions
299+
300+
You can use parameters in conditions. Parameter expansion happens before the pipeline runs and replaces values surrounded by `${{ }}` with the literal parameter values. Because parameter expansion occurs before condition evaluation, you can declare a parameter in a pipeline and embed the parameter inside any condition in that pipeline.
301+
302+
The `condition` in the following example combines two functions: `succeeded()` and `${{ eq(parameters.doThing, true) }}`. The `succeeded()` function checks if the previous step succeeded. This function returns `true` if there is no previous step.
303+
304+
The `${{ eq(parameters.doThing, true) }}` function checks whether the `doThing` parameter is equal to `true`. The script step in the following example runs because there was no previous step and `parameters.doThing` is `true` by default.
305+
306+
```yaml
307+
parameters:
308+
- name: doThing
309+
default: true
310+
type: boolean
311+
312+
steps:
313+
- script: echo I did a thing
314+
condition: and(succeeded(), ${{ eq(parameters.doThing, true) }})
315+
```
316+
317+
### Template parameters in conditions
318+
319+
When you pass a parameter to a pipeline template, you can set the parameter's value in the template file or [use templateContext to pass the parameter to the template](template-parameters.md?view=azure-devops&preserve-view=true#use-templatecontext-to-pass-properties-to-templates).
320+
321+
The following *parameters.yml* template file declares the `doThing` parameter with a default value of `true` and uses the parameter in a job condition.
322+
323+
```yaml
324+
# parameters.yml
325+
parameters:
326+
- name: doThing
327+
default: true
328+
type: boolean
329+
330+
jobs:
331+
- job: B
332+
steps:
333+
- script: echo I did a thing
334+
condition: ${{ eq(parameters.doThing, true) }}
335+
```
336+
337+
The following *azure-pipelines.yml* pipeline definition references the job in the *parameters.yml* template file. The output of the pipeline is `I did a thing` because the parameter `doThing` is true by default.
338+
339+
```yaml
340+
# azure-pipelines.yml
341+
342+
extends:
343+
template: parameters.yml
344+
```
345+
346+
For more template parameter examples, see the [Template usage reference](templates.md).
347+
352348
## FAQ
353349

354350
<!-- BEGINSECTION class="md-qanda" -->
@@ -379,4 +375,4 @@ You can experience this issue if a condition configured in a stage doesn't inclu
379375

380376
- [Specify jobs in your pipeline](phases.md)
381377
- [Add stages, dependencies, and conditions](stages.md)
382-
- [Template parameters](template-parameters.md)
378+
- [Use template parameters](template-parameters.md)

0 commit comments

Comments
 (0)