Promote artifacts between stages
- Tier: Premium, Ultimate
- Offering: GitLab.com
- Status: Beta
Artifact promotion moves an artifact that passed one stage of your release process, such as dev, into the repository for the next stage, such as staging. The artifact is not rebuilt, so what you deploy from staging is byte-for-byte what you tested in dev.
Promote artifacts when you keep one repository for each stage, and each repository should hold only artifacts that passed the stages before it.
During the beta, Artifact Central has no promote action. A pipeline promotes the artifact instead.
Promotion workflow
A promotion pipeline builds each artifact once and promotes it on a Git tag:
- A commit to the default branch builds each artifact and publishes it to the dev repository. The version or tag includes the commit SHA, so each build has its own identity.
- A protected Git tag on that commit starts a pipeline that copies the same artifact to the next stage’s repository.
- The promote jobs copy the bytes the build jobs published, and never rebuild. A rebuild produces different bytes, so what you promote would not be what you tested.
A tag pipeline runs on the tagged commit, so $CI_COMMIT_SHA and $CI_COMMIT_SHORT_SHA match
the build that published the artifacts.
The promotion demo project runs this pipeline for Maven, npm, and container images.
Prerequisites
- One hosted repository for each stage and format in the same registry, such as
app-maven-devandapp-maven-staging. - A job that exchanges
CI_JOB_TOKENfor an Artifact Central token. For more information, see use Artifact Central in CI/CD. - For Maven, a
ci-settings.xmlfile and adistributionManagementsection that point at the dev repository. For more information, see publish a Maven package. - Artifact Central roles for the user who runs each pipeline:
- Build pipeline: the Artifact Contributor role or higher on the dev repository.
- Promote pipeline: the Artifact Viewer role or higher on the dev repository, and the Artifact Contributor role or higher on the staging repository.
In the examples on this page, replace the following placeholders:
<registry_host>: Enter the hostname from your repository’s setup instructions. To find it, go to your repository and select Setup instructions.<registry_handle>: Enter your organization’s registry handle.
Add the shared job definitions
Every example on this page extends hidden jobs that keep the build and promote jobs apart.
Add them to .gitlab-ci.yml before you add a build or promote job:
stages:
- build
- promote
.version:
variables:
VERSION: 1.0.0-$CI_COMMIT_SHORT_SHA
.build:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
.promote:
stage: promote
rules:
- if: $CI_COMMIT_TAG =~ /^v/
environment:
name: stagingEvery build job extends .build, and every promote job extends .promote, so a tag pipeline
never rebuilds. The npm and Maven jobs also extend .version, so the promote job finds the
version the build job published.
Restrict who can promote
Restrict who can promote so that only approved users can move an artifact to the next stage.
The token from the exchange acts as the user who runs the job. Anyone with the Artifact Contributor role on the staging repository can publish to it from any branch, without a tag or an environment. The role on the staging repository is the control that matters. Protected tags and environments control only the promotion pipeline.
To restrict who can promote:
- Assign the Artifact Contributor role on the staging repository only to the users who can promote. Give everyone else the Artifact Viewer role or no role there. Check namespace roles too. A role on the namespace applies to every repository, and a role on a repository can only add access. Anyone with the Artifact Contributor role or higher on the namespace can publish to staging. If someone who shouldn’t promote has Artifact Contributor or higher on the namespace, give them Artifact Contributor on the repositories they publish to, then lower their namespace role to Artifact Viewer. A role change can take a minute or more, so this order avoids a window where their builds can’t publish to dev. Organization administrators always keep publish access. They get the Artifact Admin role automatically, and a lower role doesn’t lower their access. For more information, see Artifact Central roles.
- Protect a tag pattern such as
v*, so only the same users can create a tag that starts a promotion. - Add the shared job definitions. Their rules run promote
jobs only on a tag that starts with
v, in thestagingenvironment. - Protect the
stagingenvironment and add deployment approvals.
The environment’s deployment history records each promotion. Tag only a commit whose build pipeline passed.
Promote container images
Copy a container image to the staging repository by its commit SHA tag. The copy keeps the image digest.
To promote a container image:
Add a build job that pushes the image to the dev repository with the full commit SHA as its tag:
build:docker: extends: [.artifact-registry, .build] image: docker:27 services: - docker:27-dind variables: DOCKER_TLS_CERTDIR: "" DOCKER_HOST: tcp://docker:2375 IMAGE_DEV: <registry_host>/<registry_handle>/container/app-docker-dev/app before_script: - apk add --no-cache curl - !reference [.artifact-registry, before_script] script: - DOCKER_BUILDKIT=0 docker build -t "$IMAGE_DEV:$CI_COMMIT_SHA" . - echo "$AR_TOKEN" | docker login <registry_host> -u __token__ --password-stdin - docker push "$IMAGE_DEV:$CI_COMMIT_SHA"Add a promote job that copies that tag to the staging repository, then adds a tag named after the Git tag. This example uses
cranefrom the Alpine package repository:promote:docker: extends: [.artifact-registry, .promote] image: alpine:3.22 variables: IMAGE_DEV: <registry_host>/<registry_handle>/container/app-docker-dev/app IMAGE_STAGING: <registry_host>/<registry_handle>/container/app-docker-staging/app before_script: - apk add --no-cache curl crane - !reference [.artifact-registry, before_script] script: - echo "$AR_TOKEN" | crane auth login <registry_host> -u __token__ --password-stdin - crane copy "$IMAGE_DEV:$CI_COMMIT_SHA" "$IMAGE_STAGING:$CI_COMMIT_SHA" - crane tag "$IMAGE_STAGING:$CI_COMMIT_SHA" "$CI_COMMIT_TAG"
The promote job copies the image the tag points to when the job runs. If the build ran again for the same commit, the tag points to the new image. For more information, see known issues.
When both repositories are in the same registry, crane copy mounts the image’s blobs in the
staging repository instead of uploading them. The job log shows a mounted blob line for each
blob. Only the manifest is uploaded.
The alpine, docker, and node:22-alpine images do not include curl, which the token
exchange uses. Each job installs curl in its own before_script, then adds the exchange back
with !reference.
For more information, see exchange the job token.
Promote npm packages
Publish the tarball the build published to the staging repository, without packing it again.
To promote an npm package:
In the project’s
.npmrcfile, add an authentication line for each repository://<registry_host>/<registry_handle>/npm/app-npm-dev/:_authToken=${AR_TOKEN} //<registry_host>/<registry_handle>/npm/app-npm-staging/:_authToken=${AR_TOKEN}Add a build job that publishes to the dev repository with
$VERSION, such as1.0.0-36c6ff13. Publish it with--tag dev, so the pre-release version does not become thelatestdist-tag:build:npm: extends: [.artifact-registry, .build, .version] image: node:22-alpine before_script: - apk add --no-cache curl - !reference [.artifact-registry, before_script] script: - npm version "$VERSION" --no-git-tag-version - npm publish --registry "https://<registry_host>/<registry_handle>/npm/app-npm-dev/" --tag devAdd a promote job that downloads the tarball from the dev repository, then publishes that file to the staging repository:
promote:npm: extends: [.artifact-registry, .promote, .version] image: node:22-alpine variables: NPM_DEV: https://<registry_host>/<registry_handle>/npm/app-npm-dev/ NPM_STAGING: https://<registry_host>/<registry_handle>/npm/app-npm-staging/ before_script: - apk add --no-cache curl - !reference [.artifact-registry, before_script] script: - npm pack "app@$VERSION" --registry "$NPM_DEV" - npm publish "app-$VERSION.tgz" --registry "$NPM_STAGING" --tag staging
--tag staging points the staging dist-tag in the staging repository at the promoted version,
so the pre-release version does not become latest there either.
Promote Maven packages
Deploy the files the build published to the staging repository, without building them again.
To promote a Maven package:
Add a build job that sets the version to
$VERSION, such as1.0.0-36c6ff13, then deploys to the dev repository:build:maven: extends: [.artifact-registry, .build, .version] image: maven:3.9-eclipse-temurin-17 script: - mvn --batch-mode -s ci-settings.xml versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false - mvn --batch-mode -s ci-settings.xml deployAdd a promote job that downloads the JAR and POM from the dev repository, then deploys those files to the staging repository:
promote:maven: extends: [.artifact-registry, .promote, .version] image: maven:3.9-eclipse-temurin-17 variables: AR_URL: https://<registry_host>/<registry_handle>/maven FILE: com/example/app/$VERSION/app-$VERSION script: - curl -sSfL -u "gitlab-ci-token:$AR_TOKEN" -o app.jar "$AR_URL/app-maven-dev/$FILE.jar" - curl -sSfL -u "gitlab-ci-token:$AR_TOKEN" -o app.pom "$AR_URL/app-maven-dev/$FILE.pom" - mvn --batch-mode -s ci-settings.xml deploy:deploy-file -DrepositoryId=artifact-central -Durl="$AR_URL/app-maven-staging" -Dfile=app.jar -DpomFile=app.pom
The -DrepositoryId value must match the server id in ci-settings.xml.
This example promotes only the JAR and POM. A version can also have sources, Javadoc files, other
classifiers, or a Gradle .module file. Download and deploy every file the version has. Without
the .module file, Gradle consumers lose the variant metadata.
Do not rebuild the package in the promote job. A rebuilt JAR usually differs from the one the build job published, so the staging repository would hold a package you did not test.
Promotion costs
Artifact Central stores identical content once in each registry, so the promoted artifact files add nothing to the registry’s deduplicated size. Each repository keeps its own metadata, so the staging repository’s metadata adds a few KB. The staging repository’s stored size still counts the promoted files. The stored sizes of your repositories can add up to more than the registry total.
| Format | Registry storage | Data transfer |
|---|---|---|
| Container | None. The blobs are mounted. | The manifest only. |
| npm | A few KB for the staging package metadata. The tarball is deduplicated. | The job downloads and uploads the tarball. |
| Maven | A few KB for the staging maven-metadata.xml. The files are deduplicated. | The job downloads and uploads every file it promotes. |
Known issues
- Artifact Central has no artifact lock. A container tag moves when you push the same tag again, and an npm dist-tag can be changed or deleted. Deploy by image digest or by exact npm version. Maven releases already reject a deploy with different content.
- Artifact Central has no server-side copy. For npm and Maven, the job downloads and uploads the files.
- Blob mounts and deduplication work only in one registry.
- Artifact Central keeps no promotion record. The pipeline and the environment’s deployment history are the record.
- A re-run of a build for the same commit publishes a version that already exists. npm rejects it
with
409 Conflict. Maven rejects it unless every file is byte-for-byte identical, and a rebuilt JAR usually differs. A container build moves the tag to the new image, and a later promotion copies that image. For more information, see publish behavior for existing versions. - Promoting an npm version that is already in staging returns
409 Conflict. This happens when a second tag lands on the same commit, or when the promote job runs again. Staging already holds the right tarball, so skip the job. Do not rebuild.
Repository and artifact protection is planned in issue 605685.