Versioning Pipeline Artifacts
This lesson explains how to identify build output exactly, and promote it unchanged.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish packages from pipeline artifacts.
- Explain the build once, promote everywhere rule.
- Set run numbers in Azure Pipelines.
- Choose a safe identifier for container images.
Packages and pipeline artifacts
The two terms are easily confused. A package is published to a feed so that other projects can consume it as a dependency. A pipeline artifact is a file or set of files produced by a run and kept with that run, usually so that a later job or stage can deploy it. In Azure Pipelines, the publish shortcut or PublishPipelineArtifact@1 stores one, and download or DownloadPipelineArtifact@2 retrieves it. In GitHub Actions, the equivalents are actions/upload-artifact and actions/download-artifact.
Package or pipeline artifact?
Build once, promote everywhere
The central rule is to build once and promote the same artifact. If a pipeline rebuilds the application for each environment, the code deployed to production was never the code tested, because compilers, dependencies and timing can differ. The artifact should be environment-neutral, with configuration supplied at deployment time.
This has a direct consequence for versioning. The identifier must be fixed at build time, must be unique, and must lead back to the source. An artifact version usually combines a human-friendly release number with a unique part.
| Identifier | Example | Purpose |
|---|---|---|
| Release version | 2.5.0 | Meaningful to people |
| Build counter | 2.5.0.417 | Unique and ordered |
| Commit SHA | 2.5.0+7c9e2f1 | Exact link to the source |
| Date | 20261102.3 | Readable sequence |
Parts of an artifact identifier
Numbering runs in Azure Pipelines
The run number comes from the top-level name property, and it appears as Build.BuildNumber. Tokens fill in values, and $(Rev:r) adds a counter that resets when the rest of the name changes. The counter() expression gives more control, and it keeps a value per prefix.
name: 2.5.$(Rev:r)
variables:
major: 2
minor: 5
# A new counter sequence starts whenever major.minor changes
patch: $[ counter(format('{0}.{1}', variables['major'], variables['minor']), 0) ]
version: $(major).$(minor).$(patch)
steps:
- script: dotnet publish --configuration Release -p:Version=$(version) --output $(Build.ArtifactStagingDirectory)
- publish: $(Build.ArtifactStagingDirectory)
artifact: webapp-$(version)In GitHub Actions, github.run_number gives a counter that is unique to a workflow, and github.sha gives the commit. A step can write a calculated value to $GITHUB_OUTPUT for later jobs to read.
Counters and run numbers
Versioning container images
A container image tag is a label that can be moved, so latest tells you nothing about which code is running, and rollback becomes unreliable. Pipelines should tag each image with something unique, usually a commit SHA or version number.
docker build -t contoso.azurecr.io/web:2.5.417 -t contoso.azurecr.io/web:7c9e2f1 .
docker push --all-tags contoso.azurecr.io/webA tag can still be overwritten. A digest, such as web@sha256:..., is a hash of the content, so it identifies one image exactly and cannot change. Deploying by digest gives the strongest guarantee. Azure Container Registry can also lock a tag to stop it from being overwritten or deleted.
The following diagram shows one image promoted through the environments.

Tags, digests and locks
Identifying what is deployed
A team's pipeline rebuilds a container image for each environment and tags all of them latest. An incident occurs, and nobody can say which code is in production. Which changes should you make?
The pipeline should build the image once, tag it with a unique value such as the commit SHA, and deploy that same image to every environment, preferably by digest. The unique tag answers what is running, and it allows a rollback to an exact previous version. Rebuilding per environment also has to stop, since test results then say nothing about the production image. A separate latest-prod tag would keep the same weakness, because it is still a tag that moves.
Why deploy by digest rather than by tag?
Show answer
A tag can be moved, whereas a digest is a hash of the content, so it identifies exactly one image.
Exam Tips
Remember for the exam
- A package goes to a feed; a pipeline artifact stays with a run.
- Build once and promote the same artifact through environments.
- $(Rev:r) and counter() add unique numbers in Azure Pipelines.
- Avoid latest in deployments; use a SHA, version or digest.
- A digest identifies image content exactly and cannot be moved.