Default Environment Variables
Cloud Native Build
provides some default environment variables that are read-only.
If you attempt to override these default environment variables during the build process, it will not take effect.
The following are the six types of "Merging Events":
pull_request
pull_request.target
pull_request.approved
pull_request.changes_requested
pull_request.mergeable
pull_request.merged
To learn more about these events, you can refer to the Events documentation.
- Basic Variables
- Commit-related variables
- repository class variables
- Build-related variables
- CNB_BUILD_ID
- CNB_BUILD_WEB_URL
- CNB_BUILD_START_TIME
- CNB_BUILD_USER
- CNB_BUILD_USER_ID
- CNB_BUILD_STAGE_NAME
- CNB_BUILD_JOB_NAME
- CNB_BUILD_JOB_KEY
- CNB_BUILD_WORKSPACE
- CNB_BUILD_FAILED_MSG
- CNB_BUILD_FAILED_STAGE_NAME
- CNB_PIPELINE_NAME
- CNB_PIPELINE_KEY
- CNB_PIPELINE_ID
- CNB_PIPELINE_DOCKER_IMAGE
- CNB_RUNNER_IP
- CNB_CPUS
- CNB_IS_RETRY
- Merge-related variables
- CNB_PULL_REQUEST
- CNB_PULL_REQUEST_LIKE
- CNB_PULL_REQUEST_PROPOSER
- CNB_PULL_REQUEST_TITLE
- CNB_PULL_REQUEST_DESC
- CNB_PULL_REQUEST_BRANCH
- CNB_PULL_REQUEST_SHA
- CNB_PULL_REQUEST_TARGET_SHA
- CNB_PULL_REQUEST_MERGE_SHA
- CNB_PULL_REQUEST_SLUG
- CNB_PULL_REQUEST_ACTION
- CNB_PULL_REQUEST_ID
- CNB_PULL_REQUEST_IID
- CNB_PULL_REQUEST_REVIEWERS
- CNB_PULL_REQUEST_REVIEW_STATE
- CNB_REVIEW_REVIEWED_BY
- CNB_REVIEW_LAST_REVIEWED_BY
- Workspace-related variables
- Issue-related variables
# CI
true
# CNB
true
# CNB_WEB_PROTOCOL
The protocol currently used by the web, http | https
# CNB_WEB_HOST
The HOST currently used by the web
# CNB_WEB_ENDPOINT
The address currently used by the web, including the protocol, HOST, and path (if any)
# CNB_API_ENDPOINT
The current API address, including the protocol, HOST, and path (if any)
Can be used in CI to call API interfaces in conjunction with CNB_TOKEN
# CNB_GROUP_SLUG
Repository's organization path.
# CNB_GROUP_SLUG_LOWERCASE
Repository's organization path (in lowercase format)
# CNB_EVENT
The value is the name of the event that triggered the build
Event types can be found in the Events documentation
# CNB_EVENT_URL
- For builds triggered by "Merge-related events" the value is the link to the corresponding PR
- For builds triggered by "push," "branch.create," or "tag_push" events, the value is the link to the latest commit
- Otherwise, the value is an empty string
# CNB_BRANCH
- For builds triggered by "push," "branch.create," or "branch.delete" events, the value is the current branch name
- For builds triggered by "Merge-related events" the value is the branch name of the target branch
- For builds triggered by "tag_push" events, the value is the name of the tag
- For builds triggered by "custom events," the value is the corresponding branch name
- For builds triggered by a "crontab," the value is the corresponding branch name
# CNB_BRANCH_SHA
- For builds triggered by "branch.delete," the value is an empty string
- For other cases, the value of
CNB_BRANCH
is the SHA of the most recent commit
# CNB_TOKEN_USER_NAME
The username corresponding to a temporary token for users is fixed as "cnb"
# CNB_TOKEN
User token, which can be used for code submission, API calls, etc.
For pull_request
events, the permissions are:
repo-code:r
repo-pr:r
repo-issue:r
repo-notes:rw
repo-contents:r
repo-registry:r
repo-commit-status:rw
account-profile:r
For non-pull_request
events, the permissions are:
repo-code:rw
repo-pr:rw
repo-issue:rw
repo-notes:rw
repo-contents:rw
repo-registry:rw
repo-commit-status:rw
repo-cnb-trigger:rw
repo-cnb-history:r
repo-cnb-detail:r
repo-basic-info:r
repo-manage:r
account-profile:r
group-resource:r
For the meaning of permissions, refer to the Access Token
in the Personal Settings
page.
# CNB_TOKEN_FOR_AI
User token, used by AI in 'Merge-related events'.
the permissions are:
repo-notes:rw
For the meaning of permissions, refer to the Access Token
in the Personal Settings
page.
# CNB_IS_CRONEVENT
Is it a crontab task
# CNB_DOCKER_REGISTRY
Artifact repository Docker source address
# CNB_HELM_REGISTRY
Artifact repository Helm source address
# CNB_BEFORE_SHA
For builds triggered by push
, the value is the sha
of the most recent commit before the push. For push
caused by branch.create
, the value is '0000000000000000000000000000000000000000'
# CNB_COMMIT
The corresponding code sha during the build process.
- For
push
andbranch.create
triggered builds, thesha
is the last commit of the latest push. - For
tag_push
andtag_deploy.*
triggered builds, thesha
is the last commit of the specific tag. - For
auto_tag
,branch.delete
, andissue.*
events, thesha
is the last commit of the main branch. - For
pull_request.merged
triggered builds, thesha
is the merged commit. - For
pull_request.target
andpull_request.mergeable
triggered builds, thesha
is the last commit of the target branch. - For
pull_request
,pull_request.approved
, andpull_request.changes_requested
events, the code is not merged yet. Thesha
is taken from the last commit of the source branch. However, during the build process, a pre-merge is performed, where the changes are merged, and the merged content is used as the final result. - For
Workspace Events
andCustom Events
triggered builds, thesha
is the last commit of the specified branch.
# CNB_COMMIT_SHORT
The abbreviation for CNB_COMMIT
is the first 8 characters of it
# CNB_COMMIT_MESSAGE
The commit information corresponding to CNB_COMMIT
# CNB_COMMIT_MESSAGE_TITLE
The title
part of CNB_COMMIT_MESSAGE
refers to the first line
# CNB_COMMITTER
The committer corresponding to CNB_COMMIT
# CNB_COMMITTER_EMAIL
The email address corresponding to CNB_COMMITTER
# CNB_IS_TAG
For builds with a tag, the value is true
# CNB_TAG_MESSAGE
Tag Message
: For builds with a tag, this environment variable will be present- Otherwise, the value is an empty string
# CNB_TAG_RELEASE_TITLE
Release Title
: For builds with a tag, the value is only present if the release title is not empty- Otherwise, the value is an empty string
# CNB_TAG_RELEASE_DESC
Release Description
: For builds with a tag, the value is only present if the release description is not empty- Otherwise, the value is an empty string
# CNB_TAG_IS_RELEASE
Tag has corresponding Release
: For builds with a tag, if the tag has a corresponding release, the value istrue
- Otherwise, the value is
false
.
# CNB_TAG_IS_PRE_RELEASE
- For builds with a tag, if there is a corresponding release and the release is a "pre-release," then the value is
true
- Otherwise, the value is
false
.
# CNB_REPO_SLUG
The target repository path should be in the format group_slug/repo_name
.
# CNB_REPO_SLUG_LOWERCASE
The lowercase format for the target repository path
# CNB_REPO_NAME
target repository name
# CNB_REPO_ID
the id of the target repository
# CNB_REPO_URL_HTTPS
HTTPS address of the target repository
# CNB_BUILD_ID
The current build number, globally unique
# CNB_BUILD_WEB_URL
The log address of the current build
# CNB_BUILD_START_TIME
The start time of the current build in UTC format is Tue Oct 19 2021 17:09:14 GMT+0800
# CNB_BUILD_USER
The name of the triggerer for the current build
# CNB_BUILD_USER_ID
The ID of the triggerer for the current build
# CNB_BUILD_STAGE_NAME
The name of the current build stage
# CNB_BUILD_JOB_NAME
The name of the current build job
# CNB_BUILD_JOB_KEY
The unique key of the current build job within the same stage
# CNB_BUILD_WORKSPACE
The root directory of the workspace where the custom shell script is executed
# CNB_BUILD_FAILED_MSG
The error message for the failed pipeline build, which can be used in the failStages
section
# CNB_BUILD_FAILED_STAGE_NAME
The name of the failed stage in the pipeline build, which can be used in the failStages
section
# CNB_PIPELINE_NAME
当前 pipeline
的 name
,没声明时为空
# CNB_PIPELINE_KEY
The index key of the current pipeline, for example, pipeline-0
# CNB_PIPELINE_ID
The unique ID of the current pipeline, which is a globally unique string
# CNB_PIPELINE_DOCKER_IMAGE
The Docker image being used by the current pipeline, for example, alpine:latest
# CNB_RUNNER_IP
The IP address of the Runner where the current pipeline is running
# CNB_CPUS
The maximum number of CPU cores that can be used by the current pipeline during the build process
# CNB_PULL_REQUEST
- For builds triggered by a
pull_request
orpull_request.target
, the value would betrue
- Otherwise, the value would be
false
# CNB_PULL_REQUEST_LIKE
- For builds triggered by "Merge-related events" the value would be
true
- Otherwise, the value would be
false
# CNB_PULL_REQUEST_PROPOSER
- For builds triggered by "Merge-related events" the value would be the name of the person who raised the PR
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_TITLE
- For builds triggered by "Merge-related events" the value would be the title filled in when raising the PR
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_DESC
- For builds triggered by "Merge-related events" the value would be the description filled in when raising the PR
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_BRANCH
- For builds triggered by "Merge-related events" the value would be the source branch name of the initiated PR
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_SHA
- For builds triggered by "Merge-related events" the value would be the latest commit SHA of the current PR source branch
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_TARGET_SHA
- For builds triggered by "Merge-related events" the value would be the latest commit SHA of the current PR target branch
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_MERGE_SHA
- For builds triggered by the
pull_request.merged
event, the value would be the SHA of the commit after the current PR is merged - 对于由
pull_request
、pull_request.target
、pull_request.mergeable
触发的构建,值将是当前 PR 预合并后的 SHA。 - Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_SLUG
- For builds triggered by "Merge-related events" the value will be the repository slug of the source repository, such as
group_name/repo_name
- Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_ACTION
For builds triggered by "Merge-related events", the possible values are:
created
: New pull request (PR)code_update
: Source branch pushstatus_update
: When the review is approved or the CI status changes, the PR becomes mergeable Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_ID
- For builds triggered by "Merge-related events", the value will be the globally unique
id
of the current or associated PR - Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_IID
- For builds triggered by "Merge-related events", the value will be the
iid
(internal ID) of the current or associated PR in the repository - Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_REVIEWERS
- For builds triggered by "Merge-related events," the value will be a list of reviewers separated by commas (
,
) - Otherwise, the value would be an empty string
# CNB_PULL_REQUEST_REVIEW_STATE
For builds triggered by "Merge-related events"
- If there are reviewers and someone has approved the review, the value is "approve"
- If there are reviewers but no one has approved the review, the value is "unapprove"
- Otherwise, the value would be an empty string
# CNB_REVIEW_REVIEWED_BY
- For builds triggered by "Merge-related events," the value will be a list of reviewers who have approved the review, separated by commas (
,
) - Otherwise, the value would be an empty string
# CNB_REVIEW_LAST_REVIEWED_BY
- For builds triggered by "Merge-related events," the value will be the last reviewer who approved the review
- Otherwise, the value would be an empty string
# CNB_IS_NEW_BRANCH
Is the current branch a newly created branch, with a default value of false
# CNB_IS_NEW_BRANCH_WITH_UPDATE
Is the current branch a newly created branch with new commits, with a default value of false
# CNB_IS_RETRY
Is the current build triggered by a rebuild
command?
# HUSKY_SKIP_INSTALL
Making Husky compatible with a CI environment
# CNB_VSCODE_WEB_URL
The remote development address for VSCode is only available when the services
field is declared as vscode
# CNB_ISSUE_ID
- For builds triggered by
issue.*
, the value is the globally uniqueID
of the issue - Otherwise, the value would be an empty string
# CNB_ISSUE_IID
- For builds triggered by
issue.*
, the value is theiid
(internal ID) of the issue in the repository. - Otherwise, the value would be an empty string
# CNB_ISSUE_TITLE
- For builds triggered by
issue.*
, the value is thetitle
of the issue - Otherwise, the value would be an empty string
# CNB_ISSUE_DESCRIPTION
- For builds triggered by
issue.*
, the value is thedescription
of the issue - Otherwise, the value would be an empty string
# CNB_ISSUE_OWNER
- For builds triggered by
issue.*
, the value is the username of the author of the issue. - Otherwise, the value would be an empty string
# CNB_ISSUE_STATE
- For builds triggered by
issue.*
, the value is the status of the issue:open
orclosed
. - Otherwise, the value would be an empty string