Pipeline Configuration Reusability

By using the include parameter, you can split your CI file and reference CI files from the current repository or other repositories, merging the pipeline configurations using the object merge mode.

Merge strategy:

  • Merging two arrays: Appending child elements
  • Merging two objects: Overwriting keys with the same name
  • Merging an array and an object: Keeping only the array
  • Merging an object and an array: Keeping only the array

For permission control when referencing configuration files, please refer to Configuration File Reference Authorization.

# Usage Examples

include:
  # 1. Directly provide the configuration file path
  - "https://xxx/template.yml"
  - "template.yml"
  # 2. Provide an object
  # path: Configuration file path
  # ignoreError: Whether to throw an error if the configuration file is not found. true does not throw an error; false throws an error. Default is false.
  - path: "template1.yml"
    ignoreError: true
  # 3. Provide an object
  # config: Provide YAML configuration
  - config:
      main:
        push:
          - stages:
              - name: echo
                script: echo "hello world"

TIP

  1. Local .cnb.yml will override the configurations in include. Configurations in later elements of the include array will override earlier ones.
  2. Nested include is supported. The local file path in include is relative to the project root directory.
  3. Up to 50 configuration files are supported in include.
  4. Referencing files in submodules is not supported.
  5. Cross-file usage of YAML anchors is not supported.

Merge example:

# template.yaml
main:
  push:
    pipeline_2:
      env:
        ENV_KEY1: xxx
        ENV_KEY3: inner
      services:
        - docker
      stages:
        - name: echo
          script: echo 222
# .cnb.yml
include:
  - https://xxx/template.yml

main:
  push:
    pipeline_1:
      stages:
        - name: echo
          script: echo 111
    pipeline_2:
      env:
        ENV_KEY2: xxx
        ENV_KEY3: outer
      stages:
        - name: echo
          script: echo 333

Merged configuration:



 
 
 
 





 
 

 
 



main:
  push:
    pipeline_1: # New key added during merge
      stages:
        - name: echo
          script: echo 111
    pipeline_2:
      env:
        ENV_KEY1: xxx
        ENV_KEY2: xxx # New key added during merge
        ENV_KEY3: outer # Overwritten key during merge
      services:
        - docker
      stages: # Appended array during merge
        - name: echo
          script: echo 222
        - name: echo
          script: echo 333

# Advanced Example

  • Separating environment variables into a separate file
# .cnb.yml
include:
  - https://xxx/.cnb.common.yml
# .cnb.env.yml
CODE_SCAN_PATH: ./src
CDN_PATH: ./dist/cdn










 
 






# https://xxx/.cnb.common.yml
main:
  push:
    - services:
        - docker
      label:
        type:
          - MASTER
        class:
          - MAIN
      imports:
        - .cnb.env.yml # Injecting environment variables using `imports`
      stages:
        - name: View injected environment variables
          script:
            - echo $CDN_PATH
            - echo $CODE_SCAN_PATH