ci: build and push a tagged image on release tags

build-and-push only ran on main and develop, so pushing a release tag (e.g. 2.0.0) produced no image.

  • Add a rule for semver tags (^\d+\.\d+\.\d+$), the same as OEG's release pipeline.
  • Tag pipelines push $CI_REGISTRY_IMAGE:<tag>. Branch pipelines still push ci-<ref>-<sha>.
  • Tags such as v2.0.0-release still don't build.

The type, lint and test jobs already run on tag pipelines, so the image is pushed only if they pass.

Merge request reports

Loading
+3 −2
Changes for .gitlab-ci.yml: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -82,9 +82,10 @@ build-and-push:
  before_script:
    - docker info
  script:
    - export TEST_IMAGE_TAG="ci-${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}"
    - export IMAGE_TAG="${CI_COMMIT_TAG:-ci-${CI_COMMIT_REF_SLUG}-${CI_COMMIT_SHORT_SHA}}"
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
    - docker buildx build --provenance=false --network=host -t "$CI_REGISTRY_IMAGE:$TEST_IMAGE_TAG" --push .
    - docker buildx build --provenance=false --network=host -t "$CI_REGISTRY_IMAGE:$IMAGE_TAG" --push .
    - docker logout "$CI_REGISTRY"
  rules:
    - if: '$CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+$/'
    - if: '$CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "develop"'
Loading