logo
0
0
WeChat Login

CNB Auto Docker Tag Plugin

CNB Auto Docker Tag Plugin - Automatically manage Docker image tag version numbers.

Features

  • Automatically fetch all tags of a Docker image, sorted by version number
  • Intelligent version increment (supports custom rules)
  • Support multiple tag format templates
  • Output pipeline variables for subsequent steps

Tag Format Support

The plugin supports the following tag format templates:

1. Semantic Version Format

tagFormat: "v@{version}"

Examples: v1.0.1, v1.0.2, v1.1.0

Version increment rules:

  • If the image has no tags, generate initial version v1.0.1
  • Otherwise, get the latest tag (sorted by semantic version), increment rules:
    • Patch number increases by 1
    • If patch reaches 100, carry to minor version and reset patch to 0
    • If minor reaches 100, carry to major version and reset minor and patch to 0

Examples:

  • v1.0.1v1.0.2
  • v1.0.99v1.1.0
  • v1.99.99v2.0.0

2. Auto-Increment Version Format

tagFormat: "v@{auto}"

Examples: v1, v2, v3

Version increment rules:

  • If the image has no tags, generate initial version v1
  • Otherwise, get the latest tag's number and add 1

3. Date-Based Version Format

tagFormat: "@{yyyyMMdd}-v@{version}"

Examples: 20260325-v1.0.1

tagFormat: "@{yyyyMMdd}-v@{auto}"

Examples: 20260325-v1

Date handling rules:

  • @{yyyyMMdd} will be replaced with the current date (e.g., 20260325)
  • Preferentially select the latest version of the day for incrementing
  • If there is no version for the day, create a new version

Usage

Use in .cnb.yml pipeline configuration:

stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: tagFormat: "v@{version}"

Parameters

slug

  • Type: string
  • Default: Current repository path (environment variable CNB_REPO_SLUG_LOWERCASE)
  • Required: Yes
  • Description: Repository path. Not needed for same-repo operations, specify this parameter for cross-repo operations.

Example:

stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: slug: "other-owner/other-repo"

type

  • Type: string
  • Default: docker
  • Required: Yes
  • Description: Package type. Currently only supports docker.

imageName

  • Type: string
  • Default: Current repository path (environment variable CNB_REPO_SLUG_LOWERCASE)
  • Required: Yes
  • Description: Docker image name. Defaults to the same as slug, can be specified separately.

Example:

stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: imageName: "my-custom-image"

tagFormat

  • Type: string
  • Default: v@{version}
  • Required: No
  • Description: Specify tag format, supports @{version}, @{auto}, @{yyyyMMdd} placeholders.

Example:

stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: tagFormat: "@{yyyyMMdd}-v@{version}"

endpoint

  • Type: string
  • Default: Current platform's OPENAPI address (environment variable CNB_API_ENDPOINT)
  • Required: No
  • Description: Platform API address. Not needed for same-platform operations, specify this parameter for cross-platform operations, e.g., https://api.cnb.cool.

token

  • Type: string
  • Default: Current user's temporary token (environment variable CNB_TOKEN)
  • Required: No
  • Description: Platform token. Can be passed for cross-platform creation. Requires registry-related permissions.

Output Variables

The following pipeline variables will be output:

##[set-output auto-docker-tag=v1.0.1] ##[set-output auto-docker-tag-url=docker.cnb.cool/h_h/images/aws-freetier-monitor:v1.0.1]

Complete Examples

Basic Usage

main: push: - stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: tagFormat: "v@{version}" auto-docker-tag: DOCKER_TAG auto-docker-tag-url: DOCKER_TAG_URL - name: echo env script: - echo "DOCKER_TAG $DOCKER_TAG" - echo "DOCKER_TAG_URL $DOCKER_TAG_URL"

Using Date Format

main: push: - stages: - name: auto-docker-tag image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: tagFormat: "@{yyyyMMdd}-v@{auto}"

Cross-Repository Operation

main: push: - stages: - name: auto-docker-tag-other-repo image: docker.cnb.cool/r_r/auto-docker-tag:latest settings: slug: "other-owner/other-repo" imageName: "my-image" endpoint: "https://api.cnb.cool" token: "${OTHER_REPO_TOKEN}"

Error Handling

The plugin will exit with a non-zero status code, causing the pipeline to fail, in the following cases:

  • Missing parameters (token, endpoint, slug, imageName, type)
  • API call failure
  • Image not found

License

MIT License

About

- 自动获取 Docker 镜像的所有 tags,按版本号排序 - 智能版本号递增(支持自定义规则) - 支持多种 tag 格式模板 - 输出流水线变量供后续步骤使用

Language
Go98.8%
Dockerfile1.2%