logo
1
0
WeChat Login

GIT Metadata

Upload/Get/Delete metadata, metadata is an annotation for tag or commit, used to store associated data.

Mirror

cnbcool/annotations:latest

Supported Events

The following events support Upload, Get, Delete metadata operations:

  • push
  • branch.create
  • branch.delete
  • pull_request.target
  • pull_request.approved
  • pull_request.changes_requested
  • pull_request.mergeable
  • pull_request.merged
  • tag_push
  • vscode
  • auto_tag
  • tag_deploy.*
  • api_trigger*
  • web_trigger*

The following events only support Get metadata, not Upload and Delete metadata:

  • pull_request

Event Description

Metadata

Format Description

key:value format

Metadata Storage Carrier

Currently, metadata can be stored for tag or commit:

  • tag: Metadata is an annotation for tag
  • commit: Metadata is an annotation for commitId

Parameter Description

  • type: Operation type, default is ADD.
    • ADD: Upload metadata, other available parameters: data, fromJsonFile.
    • DELETE: Delete metadata, other available parameter: key
    • GET: Get metadata, other available parameter: toFile
  • data: Metadata to be uploaded. Valid when type: ADD. Supports the following two formats (choose one, \n is preferred). When using ; as separator, it cannot contain \n. Metadata key cannot be empty, empty keys will be filtered out, and can only contain 0-9, a-z, A-Z, _, -. When metadata value may contain \n or ;, it is recommended to encode the value or use fromJsonFile to input data to avoid unexpected results.
    • Separated by semicolons: key1=value1;key2=value2;key3=value3
    • Separated by line breaks: key1=value1\nkey2=value2\nkey3=value3
  • key: Supports multiple keys, separated by English semicolons, English commas, or line breaks. When type: DELETE, it indicates the metadata key to be deleted.
  • toFile: Valid when type: GET. Stores the queried data in JSON string format to the specified file, input relative path (e.g., text.json)
  • fromJsonFile: Valid when type: ADD. JSON data (e.g., {"key1": "value1","key2":"value2"}) stored in a relative path file (e.g., text.json). When both data and fromJsonFile are provided, both are effective, but for the same key, data from data takes precedence.
  • tag: Tag name, optional. Operates on metadata for the specified tag.
  • commit: commitID, long hash, optional. Operates on metadata for the specified commit.

When neither tag nor commit is provided, the default metadata carrier is:

  • tag_push and tag_deploy.* events: Default operation is on tag metadata. tag takes the environment variable CNB_BRANCH
  • Other events: Default operation is on commit metadata. commit takes the environment variable CNB_COMMIT

Usage in Cloud Native Build

Upload Metadata

main:
  # Upload metadata in push event, data is annotation for commitId
  push:
    - stages:
      - name: Upload Metadata
        image: cnbcool/annotations:latest
        settings:
          # Four ways to input data
          # Method 1: Multi-line text format example, actually separated by \n
          data: |
            key1=value1
            key2=value2
          # Method 2: Separated by semicolons
          # data: key1=value1;key2=value2
          # Method 3: Separated by \n
          # data: key1=value1\nkey2=value2
          # Method 4: Read data from file
          # fromFile: text.json
          type: ADD

$:
  # Upload metadata in tag_push event, data is annotation for tag
  tag_push:
    - stages:
      - name: Upload Metadata
        image: cnbcool/annotations:latest
        settings:
          # Four ways to input data
          # Method 1: Multi-line text format example, actually separated by \n
          data: |
            key1=value1
            key2=value2
          # Method 2: Separated by semicolons
          # data: key1=value1;key2=value2
          # Method 3: Separated by \n
          # data: key1=value1\nkey2=value2
           # Method 4: Read data from file
          # fromFile: text.json
          type: ADD

main:
  # Upload metadata for specified tag in non-tag_push/tag_deploy.* events
  api_trigger_test:
    - stages:
      - name: Upload Metadata
        image: cnbcool/annotations:latest
        settings:
          # Four ways to input data
          # Method 1: Multi-line text format example, actually separated by \n
          data: |
            key1=value1
            key2=value2
          # Method 2: Separated by semicolons
          # data: key1=value1;key2=value2
          # Method 3: Separated by \n
          # data: key1=value1\nkey2=value2
           # Method 4: Read data from file
          # fromFile: text.json
          type: ADD
          tag: v1.0.0

Delete Metadata

main:
  # Delete metadata in push event, deleting commitId metadata
  push:
    - stages:
      - name: Delete Metadata
        image: cnbcool/annotations:latest
        settings:
          # Supports semicolon, \n separation, or multi-line text
          key: key1;key2;key3
          type: DELETE

$:
  # Delete metadata in tag_push event, deleting tag metadata
  tag_push:
    - stages:
      - name: Delete Metadata
        image: cnbcool/annotations:latest
        settings:
          # Supports semicolon, \n separation, or multi-line text
          key: key1;key2;key3
          type: DELETE

main:
  # Delete metadata for specified tag in non-tag_push/tag_deploy.* events
  api_trigger_test:
    - stages:
      - name: Delete Metadata
        image: cnbcool/annotations:latest
        settings:
          # Supports semicolon, \n separation, or multi-line text
          key: key1;key2;key3
          type: DELETE
          tag: v1.0.0

Get Metadata

main:
  # Get metadata in push event, getting commitId metadata
  push:
    - stages:
      - name: Get Metadata
        image: cnbcool/annotations:latest
        settings:
          type: GET
        exports:
          # annotations is all metadata in JSON string format
          # Example: "{"key1":"value1","key2":"value2","key3":"value3"}"
          annotations: ANNOTATIONS
          key1: KEY1
          key2: KEY2
          key3: KEY3
      - name: Output Metadata
        script: 
          - echo $ANNOTATIONS
          - echo $KEY1
          - echo $KEY2
          - echo $KEY3

$:
  # Get metadata in tag_push event, getting tag metadata
  tag_push:
    - stages:
      - name: Get All Metadata
        image: cnbcool/annotations:latest
        settings:
          type: GET
        exports:
          # annotations is all metadata in JSON string format
          # Example: "{"key1":"value1","key2":"value2","key3":"value3"}"
          annotations: ANNOTATIONS
          key1: KEY1
          key2: KEY2
          key3: KEY3
      - name: Output Metadata
        script: 
          - echo $ANNOTATIONS
          - echo $KEY1
          - echo $KEY2
          - echo $KEY3

main:
  # Get metadata for specified tag in non-tag_push/tag_deploy.* events
  api_trigger_test:
    - stages:
      - name: Get All Metadata
        image: cnbcool/annotations:latest
        settings:
          type: GET
          tag: v1.0.0
        exports:
          # annotations is all metadata in JSON string format
          # Example: "{"key1":"value1","key2":"value2","key3":"value3"}"
          annotations: ANNOTATIONS
          key1: KEY1
          key2: KEY2
          key3: KEY3
      - name: Output Metadata
        script: 
          - echo $ANNOTATIONS
          - echo $KEY1
          - echo $KEY2
          - echo $KEY3

About

上传元数据

664.00 KiB
1 forks0 stars2 branches1 TagREADMEMIT license
Language
TypeScript62.9%
Shell23.1%
JavaScript10.1%
Dockerfile3.9%