apply

cnb:apply

Specify the configuration file, bind it to the current Git repository, and execute the specified event pipeline.

# Applicable Events

  • push
  • branch.create
  • pull_request.target
  • pull_request.mergeable
  • tag_push
  • pull_request.merged
  • api_trigger
  • web_trigger
  • crontab
  • tag_deploy

# Parameters

# config

  • type: String
  • required: false

The complete content of the CI configuration file

# configFrom

  • type: String
  • required: false

Specify a local file as the configuration file.

# event

  • type: String
  • required: false
  • default: api_trigger

The custom event name to be executed must be either api_trigger or start with api_trigger_.

# sync

  • type: Boolean
  • required: false
  • default: false

Whether to execute synchronously.

In synchronous mode, it waits for the current apply pipeline to execute successfully before proceeding to the next task.

# continueOnBuildError

  • type: Boolean
  • required: false
  • default: false

In synchronous mode, should the execution of the next task continue when the triggered pipeline build fails?

# ignoreGitStatus

  • type: Boolean
  • required: false
  • default: false

Whether to ignore the git status setting.

After ignoring it, the pipeline will not appear in the "commit checks".

# Environment Variables

All business-defined environment variables visible to the current job are passed to the new pipeline.

The following environment variables are included in the default values, which cannot be overridden by users:

  • APPLY_TRIGGER_BUILD_ID, with the same meaning as the CNB_BUILD_ID environment variable in CI
  • APPLY_TRIGGER_PIPELINE_ID, with the same meaning as the CNB_PIPELINE_ID environment variable in CI
  • APPLY_TRIGGER_REPO_SLUG, with the same meaning as the CNB_REPO_SLUG environment variable in CI
  • APPLY_TRIGGER_REPO_ID, with the same meaning as the CNB_REPO_ID environment variable in CI
  • APPLY_TRIGGER_USER, with the same meaning as the CNB_BUILD_USER environment variable in CI
  • APPLY_TRIGGER_BRANCH, with the same meaning as the CNB_BRANCH environment variable in CI
  • APPLY_TRIGGER_COMMIT, with the same meaning as the CNB_COMMIT environment variable in CI
  • APPLY_TRIGGER_COMMIT_SHORT, with the same meaning as the CNB_COMMIT_SHORT environment variable in CI
  • APPLY_TRIGGER_ORIGIN_EVENT, with the same meaning as the CNB_EVENT environment variable in CI
  • CNB_PULL_REQUEST_ID, with the same meaning as the CNB_PULL_REQUEST_ID environment variable in CI
  • CNB_PULL_REQUEST_IID, with the same meaning as the CNB_PULL_REQUEST_IID environment variable in CI
  • CNB_PULL_REQUEST_MERGE_SHA, with the same meaning as the CNB_PULL_REQUEST_MERGE_SHA environment variable in CI

# Configuration Value Priority

The configuration values are retrieved in the following order until a value is found:

  1. config
  2. configFrom
  3. Current repository's .cnb.yml file
    1. If the apply built-in task is called within the pull_request.merged event, the merged configuration file is used.
    2. If the apply built-in task is called within the pull_request.target or pull_request.mergeable events, the configuration file from the target branch is used.
    3. In other cases, the configuration file from the current branch is used.

Note that configFrom only supports local files such as ./test/.cnb.yml. For remote files, you need to download them locally beforehand.

# Output Results

{
  "sn": "cnb-i5o-1ht8e12hi", // Build number
  "buildLogUrl": "http://xxx.com/my-group/my-repo/-/build/logs/cnb-i5o-1ht8e12hi", // Build log URL
  "message": "success",
  "buildSuccess": true, // Whether the triggered build is successful, this key only exists in synchronous mode
  "lastJobExports": {} // Environment variables exported by the last job in the triggered pipeline
}

# Configuration Examples

main:
  push:
    - stages:
        - name: trigger
          type: cnb:apply
          options:
            configFrom: ./test/.cnb.yml
            event: api_trigger_test
main:
  push:
    - stages:
        - name: trigger
          type: cnb:apply
          options:
            config: |
              main:
                api_trigger_test: 
                - stages:
                  - name: test
                    script: echo test
            event: api_trigger_test
main:
  push:
    - stages:
        - name: trigger
          type: cnb:apply
          options:
            # Execute other events defined in the current configuration file
            event: api_trigger_test
  api_trigger_test:
    - stages:
        - name: test
          script: echo test
main:
  push:
    - stages:
        - name: trigger
          type: cnb:apply
          options:
            configFrom: .xxx.yml
            event: api_trigger_get_alpha
            sync: true