<p>Five minutes later I found this dealt with at <a href="https://github.com/MicrosoftDocs/azure-devops-docs/issues/7738" rel="nofollow noreferrer">https://github.com/MicrosoftDocs/azure-devops-docs/issues/7738</a>. Indeed, it appears that the Succeed outcome is not set until a stage has actually been executed. One respondent in the discussion indicates that this has worked for them:</p>
<blockquote>
<p>As a work-around, our team has had success (no pun intended) using:</p>
<p><code>condition: not(or(failed(), canceled())</code></p>
<p>This works because the previous stage being skipped does not set a failed status.</p>
</blockquote>

CC BY-SA 4.0
2024-07-11T16:20:12.707Z
@Nikola Malešević I rejected your edit proposal because the indentation is intentional, demarcating a quoted passage from the other discussion.
Green Grasso Holm
CC BY-SA 4.0
2024-08-03T19:24:49.780Z
Slight syntax error in your work-around. Missing closing parenthesis for `not`. The corrected line is thus `condition: not(or(failed(), cancelled()))`
teh4x
CC BY-SA 4.0
2022-11-08T13:54:26.263Z
2022-11-08T13:54:26.263Z
Green Grasso Holm
<p>In an Azure DevOps pipeline, what is the value of Agent.JobStatus before any stages have been run? Is it initialized to 'Succeeded' or is it initially undefined or set to null or something like that, only to be set to 'Succeeded' after the first successful execution?</p>
<p>In other words:</p>
<ul>
<li>If I include <code>succeeded()</code> (which is the same thing as, <code>in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues')</code>) in a condition for running the first stage, is it going to return true even though there have been no previous stages to return a successful result?</li>
<li>If I include <code>succeeded()</code> in a conditional for running the second stage, where the first stage has a condition that evaluated to false so the first stage was skipped, will it be true even though no previous stages have been <em>executed</em> returning a successful result?</li>
</ul>
<p>The way I'd like to think it works is such that <code>succeeded</code> will return <code>true</code> in both places where I use it in the following code, where I want the first stage to run if the original triggering repo branch was 'main' and the second stage to run if the original branch was 'release/*'. (This is a slightly simplified version of the actual logic.) Am I correct?</p>
<pre><code>stages:
  - template: my-template.yml
    condition: and(succeeded(), eq(variables['resources.pipeline.previousPipeline.SourceBranch'], 'refs/heads/main'))
    parameters:
      ...
  - template: my-template.yml
    condition: and(succeeded(), startsWith(variables['resources.pipeline.previousPipeline.SourceBranch'], 'refs/heads/release/'))
    parameters:
      ...
</code></pre>
<p>Alternatively, if <code>succeeded()</code> doesn't work in this manner, would I get what I need if, instead, I were to use <code>not(failed())</code>?</p>

<azure-devops><azure-pipelines>
Value of succeeded() in Azure DevOps pipeline before first stage is run
Green Grasso Holm
# Value of succeeded() in Azure DevOps pipeline before first stage is run

(Asked by: username_0 on 2022-11-08)

In an Azure DevOps pipeline, what is the value of Agent.JobStatus before any stages have been run? Is it initialized to 'Succeeded' or is it initially undefined or set to null or something like that, only to be set to 'Succeeded' after the first successful execution?
In other words:

If I include succeeded() (which is the same thing as, in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues')) in a condition for running the first stage, is it going to return true even though there have been no previous stages to return a successful result?
If I include succeeded() in a conditional for running the second stage, where the first stage has a condition that evaluated to false so the first stage was skipped, will it be true even though no previous stages have been executed returning a successful result?

The way I'd like to think it works is such that succeeded will return true in both places where I use it in the following code, where I want the first stage to run if the original triggering repo branch was 'main' and the second stage to run if the original branch was 'release/*'. (This is a slightly simplified version of the actual logic.) Am I correct?
stages:
  - template: my-template.yml
    condition: and(succeeded(), eq(variables['resources.pipeline.previousPipeline.SourceBranch'], 'refs/heads/main'))
    parameters:
      ...
  - template: my-template.yml
    condition: and(succeeded(), startsWith(variables['resources.pipeline.previousPipeline.SourceBranch'], 'refs/heads/release/'))
    parameters:
      ...

Alternatively, if succeeded() doesn't work in this manner, would I get what I need if, instead, I were to use not(failed())?

**Tags:** azure-devops, azure-pipelines


---

## 1 answers

### Answer by username_0 on 2022-11-08. Score: 1 | Accepted answer

Five minutes later I found this dealt with at <https://github.com/MicrosoftDocs/azure-devops-docs/issues/7738>. Indeed, it appears that the Succeed outcome is not set until a stage has actually been executed. One respondent in the discussion indicates that this has worked for them:

> As a work-around, our team has had success (no pun intended) using:
>
> `condition: not(or(failed(), canceled())`
>
> This works because the previous stage being skipped does not set a failed status.

> **Comments:**
> **username_0**: @Nikola Malešević I rejected your edit proposal because the indentation is intentional, demarcating a quoted passage from the other discussion.  
> **username_1**: Slight syntax error in your work-around. Missing closing parenthesis for `not`. The corrected line is thus `condition: not(or(failed(), cancelled()))`  

---

