From 034656a22890de7af0fe1db30b0da171f1304e2e Mon Sep 17 00:00:00 2001 From: Dan Notestein Date: Thu, 18 Dec 2025 14:50:14 -0500 Subject: [PATCH] Add skip variables to deployment templates Add configurable skip variables to control which jobs run in a pipeline: - QUICK_TEST: Skip all deployments (dev and production) - SKIP_PRODUCTION_DEPLOY: Skip production deployments only - SKIP_DEV_DEPLOY: Skip dev package deployments only - SKIP_NPM_PUBLISH: Skip all npm publishing - SKIP_DOCKER_PUBLISH: Skip Docker Hub publishing These variables are checked in template rules, so projects that extend templates without overriding rules automatically get this behavior. Updated templates: - .npm_deploy_package_template (dev npm to GitLab registry) - .registry_npmjs_org_deploy_package_template (production npm to npmjs.org) - .publish_docker_image_template (production Docker to Docker Hub) This allows fine-grained control over pipeline behavior without requiring projects to override template rules (which is error-prone and can accidentally remove important protections like protected-tag checks). --- README.md | 15 +++++++++++ templates/docker_image_jobs.gitlab-ci.yml | 15 +++++++++++ templates/npm_projects.gitlab-ci.yml | 32 +++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc0edf5..7d5649e 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,23 @@ This project contains the common CI templates and scripts for Hive and Hive-rela ## Job templates - [docker_image_jobs.gitlab-ci.yml](templates/docker_image_jobs.gitlab-ci.yml) - templates for managing Docker images +- [npm_projects.gitlab-ci.yml](templates/npm_projects.gitlab-ci.yml) - templates for NPM package building and publishing - [test_jobs.gitlab-ci.yml](templates/test_jobs.gitlab-ci.yml) - templates for running tests +## Pipeline Skip Variables + +The following variables can be set to `"true"` when running a pipeline to skip certain jobs: + +| Variable | Effect | +|----------|--------| +| `QUICK_TEST` | Skip all production deployments and dev package deployments | +| `SKIP_PRODUCTION_DEPLOY` | Skip all production deployments (npm to npmjs.org, Docker to Docker Hub) | +| `SKIP_DEV_DEPLOY` | Skip dev package deployments (npm to internal GitLab registry) | +| `SKIP_NPM_PUBLISH` | Skip all npm publishing jobs (both dev and production) | +| `SKIP_DOCKER_PUBLISH` | Skip Docker Hub publishing jobs | + +These variables are checked in the template rules, so projects that extend templates without overriding rules automatically get this behavior. + ## Example jobs The GitLab CI configuration for this repository contains example jobs based on the templates defined in it. On top of that the Docker images are built by jobs also based on said templates. diff --git a/templates/docker_image_jobs.gitlab-ci.yml b/templates/docker_image_jobs.gitlab-ci.yml index 771f3ad..351bcf3 100644 --- a/templates/docker_image_jobs.gitlab-ci.yml +++ b/templates/docker_image_jobs.gitlab-ci.yml @@ -63,6 +63,15 @@ include: tags: - public-runner-docker +# Template for publishing Docker images to Docker Hub (PUBLIC production registry). +# +# IMPORTANT: This template publishes to the PUBLIC Docker Hub registry! +# By default, only runs on protected tags. +# +# Skip variables (set to "true" to skip this job): +# - QUICK_TEST: Skip during quick test pipelines +# - SKIP_PRODUCTION_DEPLOY: Skip all production deployments +# - SKIP_DOCKER_PUBLISH: Skip all Docker Hub publishing jobs .publish_docker_image_template: extends: .docker_image_builder_job_template needs: [] @@ -70,6 +79,12 @@ include: DOCKER_HUB_USER: $DOCKER_HUB_USER DOCKER_HUB_PASSWORD: $DOCKER_HUB_PASSWORD rules: + - if: $QUICK_TEST == "true" + when: never + - if: $SKIP_PRODUCTION_DEPLOY == "true" + when: never + - if: $SKIP_DOCKER_PUBLISH == "true" + when: never - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: on_success - when: never diff --git a/templates/npm_projects.gitlab-ci.yml b/templates/npm_projects.gitlab-ci.yml index d2a19dd..066e222 100644 --- a/templates/npm_projects.gitlab-ci.yml +++ b/templates/npm_projects.gitlab-ci.yml @@ -181,8 +181,13 @@ variables: expire_in: 1 week -# Base definition for NPM package publishing job. +# Base definition for NPM package publishing job (to internal GitLab registry). # The derived job, should have in its dependencies a final job performing a npm-build (derived from `.npm_build_template`) +# +# Skip variables (set to "true" to skip this job): +# - QUICK_TEST: Skip during quick test pipelines +# - SKIP_DEV_DEPLOY: Skip dev package deployments specifically +# - SKIP_NPM_PUBLISH: Skip all npm publishing jobs .npm_deploy_package_template: extends: .npm_process_built_package_tarball variables: @@ -200,8 +205,25 @@ variables: - /home/emscripten/scripts/npm_publish.sh "${SOURCE_DIR}" "${NPM_REGISTRY_URL}" "${NPM_PACKAGE_SCOPE}" "${NPM_PUBLISH_TOKEN}" - echo -e "\e[0Ksection_end:$(date +%s):publishing\r\e[0KDone" -# Base definition for NPM package publishing job to the registry.npmjs.org. + rules: + - if: $QUICK_TEST == "true" + when: never + - if: $SKIP_DEV_DEPLOY == "true" + when: never + - if: $SKIP_NPM_PUBLISH == "true" + when: never + - when: on_success + +# Base definition for NPM package publishing job to the registry.npmjs.org (PUBLIC production registry). # The derived job, should have in its dependencies a final job performing a npm-build (derived from `.npm_build_template`) +# +# IMPORTANT: This template publishes to the PUBLIC npmjs.org registry! +# By default, only runs on protected tags with manual trigger. +# +# Skip variables (set to "true" to skip this job): +# - QUICK_TEST: Skip during quick test pipelines +# - SKIP_PRODUCTION_DEPLOY: Skip all production deployments +# - SKIP_NPM_PUBLISH: Skip all npm publishing jobs .registry_npmjs_org_deploy_package_template: extends: .npm_process_built_package_tarball variables: @@ -222,6 +244,12 @@ variables: - echo -e "\e[0Ksection_end:$(date +%s):publishing\r\e[0KDone" rules: + - if: $QUICK_TEST == "true" + when: never + - if: $SKIP_PRODUCTION_DEPLOY == "true" + when: never + - if: $SKIP_NPM_PUBLISH == "true" + when: never - if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"' when: manual allow_failure: true -- GitLab