Courseiva
Design and implement build and release pipelineshardMultiple ChoiceObjective-mapped

Fixing a counter() Expression That Never Increments Past Zero

Network Topology
configuration $(buildConfiguration)""arguments": "configuration $output $(Build.ArtifactStagingDirectory)"Refer to the exhibit.```json"variables": {"buildConfiguration": "Release","majorVersion": "1","minorVersion": "0","revision": $[counter(variables['minorVersion'], 0)]},"steps": ["task": "DotNetCoreCLI@2","inputs": {"command": "build","command": "publish",```

Refer to the exhibit. You have a YAML pipeline definition that builds a .NET application. You notice that the revision number is always 0. What is the most likely cause?

Quick Answer

A revision number that's always 0 means the counter() expression's seed variable isn't actually a named counter — Azure Pipelines counters persist their value across runs only when tied to a real counter variable. If the variable used as the seed is just a regular pipeline variable, the counter resets to its starting value on every run instead of incrementing.

⚠ Common exam trap

Many exam-takers assume the counter expression automatically increments without needing the first argument to be a persistent counter variable, leading them to overlook the requirement that the variable used as the counter name must be defined as a counter in the pipeline.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The counter expression uses a variable that is not defined as a counter, causing it to reset.

The counter expression in Azure DevOps YAML pipelines requires a named counter variable to persist its value across pipeline runs. If the variable used as the first parameter of the `counter` function (e.g., `minorVersion`) is not defined as a counter variable, the counter resets to the seed value (0) on each run. Option B correctly identifies that the variable is not defined as a counter, causing the revision number to always be 0.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The 'DotNetCoreCLI@2' task does not support the counter expression.

    Why it's wrong here

    The counter expression is a pipeline feature, not a task feature.

  • The counter expression uses a variable that is not defined as a counter, causing it to reset.

    Why this is correct

    The seed should be a static value or a counter itself; using a non-counter variable as seed resets the counter each run.

  • The counter expression resets every time the pipeline runs because of the 'minorVersion' variable.

    Why it's wrong here

    The counter should persist across runs, but the seed being a variable causes it to reset to 0 each run.

  • The counter expression is evaluated after the build steps, so it always returns 0.

    Why it's wrong here

    The counter is evaluated at pipeline start, not after steps.

About these practice questions

This AZ-400 question is part of Courseiva's 823-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on AZ-400

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. You have the YAML pipeline snippet shown in the exhibit. The first run produces version 1.0.0. What will be the version produced on the third run?

hard
  • A.1.0.1
  • B.1.0.3
  • C.1.0.2
  • D.1.0.0

Why C: The YAML pipeline uses a counter expression `$[counter(format('{0}.{1}', variables['major'], variables['minor']), 0)]` for the patch version. The counter starts at 0 for the first run, producing version 1.0.0. Each subsequent run increments the counter by 1, so the second run produces 1.0.1, and the third run produces 1.0.2. Therefore, option C is correct.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.