AZ-400 exam dumps

AZ-400 practice question 139 of 306

Designing and Implementing Microsoft DevOps Solutions. Professional level, Microsoft. Free question with the correct answer and a full explanation.

AZ-400 Question 139

Single answer

You are configuring an Azure DevOps multi-stage pipeline using YAML to build a .NET application and run automated tests. You have defined a 'Build' stage and a separate 'Test' stage. You want to ensure the 'Test' stage only runs if the 'Build' stage completes successfully. Which YAML snippet correctly fulfills this requirement for the 'Test' stage?

  1. A

    A) stage: Test dependsOn: Build condition: succeeded() jobs: - job: runTests steps: - script: dotnet test

  2. B

    B) stage: Test condition: succeeded(Build) jobs: - job: runTests steps: - script: dotnet test

  3. C

    C) stage: Test dependsOn: Build jobs: - job: runTests condition: failed() steps: - script: dotnet test

  4. D

    D) stage: Test dependsOn: Build jobs: - job: runTests steps: - script: dotnet test condition: always()

Show answer and explanation

Correct answer: A

Explanation

In Azure DevOps multi-stage YAML pipelines, you typically use 'dependsOn' and 'condition: succeeded()' to control the sequence of stages. 'dependsOn: Build' indicates that the 'Test' stage depends on the 'Build' stage, and 'condition: succeeded()' ensures the stage runs only if the dependent stage completes successfully. For more details, refer to the official Azure DevOps documentation on stage dependencies and conditions: https://docs.microsoft.com/azure/devops/pipelines/process/stages.

  • A. Correct.

    Option A is correct. In Azure DevOps pipelines, adding 'dependsOn: Build' ensures that this stage only runs if the 'Build' stage is started, and 'condition: succeeded()' ensures it only proceeds if the previous stage is successful. This is the recommended approach when chaining multiple stages in YAML pipelines.

  • B. Incorrect.

    Option B is incorrect. 'condition: succeeded(Build)' is not valid syntax in Azure DevOps YAML. Conditions do not take stage names as parameters this way. Instead, you use 'succeeded()' to indicate the outcome of the stage or job it depends on.

  • C. Incorrect.

    Option C is incorrect. It sets 'condition: failed()' on the 'runTests' job, which means the tests would only run if the 'Build' stage (or a previous job) fails. This is the opposite of the desired outcome.

  • D. Incorrect.

    Option D is incorrect. 'condition: always()' would let the tests run even if the 'Build' stage fails. This does not meet the requirement of only running tests upon a successful build.

Timed practice exam

Take a AZ-400 practice test under exam conditions

70 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam