AZ-400 Question 140
Single answerYou manage an Azure DevOps repository that includes a multi-stage pipeline for an ASP.NET Core application. The pipeline defines a Build stage, a Test stage, and a Deploy stage. The Build stage compiles the source code, the Test stage runs unit tests, and the Deploy stage publishes the application to an Azure web app. You want to ensure the Deploy stage only runs if the Build stage completes successfully, regardless of the Test stage results. Which YAML snippet correctly enforces this behavior?
- A
A) - stage: Deploy dependsOn: Build condition: succeeded() jobs: - job: DeployJob steps: - task: AzureWebAppDeploy@4
- B
B) - stage: Deploy dependsOn: Build condition: always() jobs: - job: DeployJob steps: - task: AzureWebAppDeploy@4
- C
C) - stage: Deploy extends: Build jobs: - job: DeployJob steps: - task: AzureWebAppDeploy@4
- D
D) - stage: Deploy dependsOn: Test condition: succeeded() jobs: - job: DeployJob steps: - task: AzureWebAppDeploy@4
Show answer and explanation
Correct answer: A
Explanation
In Azure DevOps YAML pipelines, you use 'dependsOn' to specify which stage(s) must complete before the current stage can run. If you only want a stage to run on a successful outcome of its dependency, you add 'condition: succeeded()'. Microsoft� documentation (https://learn.microsoft.com/azure/devops/pipelines/get-started/multi-stage-pipelines) outlines that 'dependsOn' defines the dependency graph between stages and that you can combine it with conditional expressions (e.g., succeeded()) to control execution flow based on success/failure of previous stages.
- A. Correct.
Option A is correct. Setting 'dependsOn: Build' ensures the Deploy stage waits for the Build stage to finish, and 'condition: succeeded()' restricts it to only run if the Build stage completes successfully. This setup matches the requirement that Deploy should only run after a successful Build, ignoring the Test stage result.
- B. Incorrect.
Option B is incorrect because 'condition: always()' causes the Deploy stage to run even if the Build stage fails or if an earlier stage fails. This does not satisfy the requirement that Deploy should only run after a successful Build.
- C. Incorrect.
Option C is incorrect because 'extends: Build' is not a valid Azure Pipelines YAML property for defining a dependent stage. In Azure Pipelines, 'dependsOn' is used to specify stage dependencies, not 'extends'.
- D. Incorrect.
Option D is incorrect because 'dependsOn: Test' means the Deploy stage will wait for (and succeed depending on) the Test stage instead of the Build stage. This does not fulfill the requirement to link Deploy directly to a successful Build.