AZ-400 Question 107
Single answerYou manage an internal NuGet feed in Azure DevOps for your company's .NET microservices. Each pipeline produces a NuGet package artifact that must clearly identify both the Git commit and the build number of the pipeline. You want to implement a sustainable versioning strategy so team members can trace issues back to a specific build and commit. Which approach should you implement to achieve this goal?
- A
Use a manual process to increment the version in the .csproj file before each commit, and upload packages using the updated version from source control only.
- B
Configure the pipeline to generate a package version dynamically by combining the current semantic version with the build ID and a substring of the Git commit hash.
- C
Set the artifact name to the pipeline run number alone (e.g., '1.0.0-from-build-1234') but store the commit hash in a separate text file within the artifact.
- D
Create a shared variable group that increments a global counter on each build and append this counter to a fixed version, ignoring the commit details.
Show answer and explanation
Correct answer: B
Explanation
In Azure DevOps, it is recommended to automate versioning by combining semantic versions with build information (such as the build ID) and the commit identifier. This ensures every artifact is consistently identifiable and traceable back to the source code. Refer to Microsoft Docs on 'Versioning in Azure DevOps Pipelines' for detailed best practices on ensuring consistent and traceable artifact versioning.
- A. Incorrect.
Option 1: Incorrect. Relying on a purely manual process to update the version in source control is error-prone and does not guarantee that every commit will have the correct version in the package. This approach can lead to out-of-sync versions and is less reliable for tracking.
- B. Correct.
Option 2: Correct. Combining the semantic version (e.g., '1.0.0') with automatically generated build information such as the pipeline build ID (e.g., 1234) and a substring of the commit hash (e.g., 'abcdef') ensures each artifact is both human-readable and fully traceable. This follows recommended best practices in Azure DevOps for automated versioning.
- C. Incorrect.
Option 3: Incorrect. While including the pipeline run number is helpful, storing the commit hash in a separate file is cumbersome. It makes it more difficult to track which package version correlates to the commit. Ideally, the commit reference is part of the version for direct traceability.
- D. Incorrect.
Option 4: Incorrect. Incrementing a global counter on each build addresses some uniqueness concerns, but ignoring the commit details means you cannot easily trace a package back to the exact source commit.