Built-in Environment Variables
About 1397 wordsAbout 5 min
Cloud Native Build
includes some default environment variables that are read-only. Attempting to override these variables during builds will not take effect.
The following merge-related events
include:
pull_request
pull_request.update
pull_request.target
pull_request.approved
pull_request.changes_requested
pull_request.mergeable
pull_request.merged
pull_request.comment
Learn more about trigger events.
Basic Variables
CI
true
CNB
true
CNB_WEB_PROTOCOL
Current web protocol: http | https
CNB_WEB_HOST
Current web address including protocol, HOST, and path (if any)
CNB_WEB_ENDPOINT
Current API endpoint including protocol, HOST, and path (if any)
Can be used with CNB_TOKEN
to call API interfaces in CI
CNB_API_ENDPOINT
Current API endpoint including protocol, HOST, and path (if any)
Can be used with CNB_TOKEN
to call API interfaces in CI
CNB_GROUP_SLUG
Repository organization path
CNB_GROUP_SLUG_LOWERCASE
Repository organization path (lowercase format)
CNB_EVENT
Name of the event that triggered the build
Event types see events
CNB_EVENT_URL
- For builds triggered by merge-related events, value is the
Pull Request
link - For builds triggered by
push
,branch.create
,tag_push
, value is the latestCommit
link - Otherwise empty string
CNB_BRANCH
- For builds triggered by
push
,branch.create
,branch.delete
, value is current branch name - For builds triggered by
merge-related events
, value is target branch name - For builds triggered by
tag_push
, value istag
name - For builds triggered by
custom events
, value is corresponding branch name - For builds triggered by
crontab
, value is corresponding branch name
CNB_BRANCH_SHA
- For builds triggered by
branch.delete
, empty string - Otherwise latest commit
sha
ofCNB_BRANCH
CNB_TOKEN_USER_NAME
Temporary token username, fixed as cnb
CNB_TOKEN
User token for code submission, API calls, etc.
For pull_request events, permissions include:
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, permissions include:
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
Refer to permissions in Personal Settings > Access Tokens
CNB_TOKEN_FOR_AI
User token used by AI in merge-related events
Permissions:
- repo-notes:rw
Refer to permissions in Personal Settings > Access Tokens
CNB_IS_CRONEVENT
Whether it's a scheduled task event
CNB_DOCKER_REGISTRY
Artifact Docker registry address
CNB_HELM_REGISTRY
Artifact Helm registry address
Commit Variables
CNB_BEFORE_SHA
For builds triggered by push
, value is the latest commit sha
before push
. For push
caused by branch.create
, value is '0000000000000000000000000000000000000000'
CNB_COMMIT
Commit sha corresponding to the build:
- For builds triggered by
push
,branch.create
, it's the latest commitsha
- For builds triggered by
tag_push
,tag_deploy.*
, it's the latest commitsha
of thetag
- For builds triggered by
auto_tag
,branch.delete
,issue.*
, it's the latest commitsha
of the main branch - For builds triggered by
pull_request.merged
, it's the mergedsha
- For builds triggered by
pull_request.target
,pull_request.mergeable
, it's the latest commitsha
of the target branch - For builds triggered by
pull_request
,pull_request.approved
,pull_request.changes_requested
,pull_request.comment
, code hasn't been actually merged yet, takes the latest commitsha
of the source branch, but the build will perform a pre-merge, meaning the merged content will be the final result - For builds triggered by
Workspaces
,custom events
, it's the latest commitsha
of the specified branch
CNB_COMMIT_SHORT
Short version of CNB_COMMIT
, taking the first 8 characters
CNB_COMMIT_MESSAGE
Commit message corresponding to CNB_COMMIT
CNB_COMMIT_MESSAGE_TITLE
The title
part of CNB_COMMIT_MESSAGE
, i.e., the first line
CNB_COMMITTER
Committer corresponding to CNB_COMMIT
CNB_COMMITTER_EMAIL
Email corresponding to CNB_COMMITTER
CNB_IS_TAG
For builds where the branch is a Tag
, value is true
CNB_TAG_MESSAGE
Tag message
: For builds where the branch is aTag
, this environment variable exists- Otherwise empty string
CNB_TAG_RELEASE_TITLE
Release title
: For builds where the branch is aTag
, ifRelease
title is not empty, there will be a value- Otherwise empty string
CNB_TAG_RELEASE_DESC
Release description
: For builds where the branch is aTag
, andRelease
description is not empty, there will be a value- Otherwise empty string
CNB_TAG_IS_RELEASE
Whether Tag has corresponding Release
: For builds where the branch is a Tag, ifTag
has correspondingRelease
, then true- Otherwise
false
CNB_TAG_IS_PRE_RELEASE
- For builds where the branch is a Tag, if corresponding
Release
exists, andRelease
is pre-release, then value istrue
- Otherwise false
CNB_IS_NEW_BRANCH
Whether current branch is newly created, default false
CNB_IS_NEW_BRANCH_WITH_UPDATE
Whether current branch is newly created and has new commits, default false
Repository Variables
CNB_REPO_SLUG
Target repository path in format group_slug/repo_name
, group_slug/sub_gourp_slog/.../repo_name
CNB_REPO_SLUG_LOWERCASE
Target repository path in lowercase format
CNB_REPO_NAME
Target repository name
CNB_REPO_NAME_LOWERCASE
Target repository name in lowercase format
CNB_REPO_ID
Target repository id
CNB_REPO_URL_HTTPS
Target repository https address
Build Variables
CNB_BUILD_ID
Current build serial number, globally unique
CNB_BUILD_WEB_URL
Current build log address
CNB_BUILD_START_TIME
Current build start time in UTC format, example Tue, 24 Dec 2024 07:42:58 GMT
CNB_BUILD_USER
Current build triggerer name
CNB_BUILD_USER_ID
Current build triggerer id
CNB_BUILD_STAGE_NAME
Current build stage
name
CNB_BUILD_JOB_NAME
Current build job
name
CNB_BUILD_JOB_KEY
Current build job
key, unique within same stage
CNB_BUILD_WORKSPACE
Custom shell
script execution workspace root directory
CNB_BUILD_FAILED_MSG
Pipeline build failure error message, can be used in failStages
CNB_BUILD_FAILED_STAGE_NAME
Pipeline build failure stage
name, can be used in failStages
CNB_PIPELINE_NAME
Current pipeline
name
, empty if not declared
CNB_PIPELINE_KEY
Current pipeline
index key
, e.g. pipeline-0
CNB_PIPELINE_ID
Current pipeline
id
, globally unique string
CNB_PIPELINE_DOCKER_IMAGE
Current pipeline
used docker image
, e.g.: alpine:latest
CNB_RUNNER_IP
Current pipeline
Runner
ip
CNB_CPUS
Maximum CPU
cores available for current build pipeline
CNB_IS_RETRY
Whether current build was triggered by rebuild
HUSKY_SKIP_INSTALL
Husky compatibility in ci environment
Merge-Related Variables
CNB_PULL_REQUEST
- For builds triggered by
pull_request
,pull_request.update
,pull_request.target
, value istrue
- Otherwise
false
CNB_PULL_REQUEST_LIKE
- For builds triggered by
merge-related events
, value istrue
- Otherwise
false
CNB_PULL_REQUEST_PROPOSER
- For builds triggered by
merge-related events
, value is PR proposer name - Otherwise empty string
CNB_PULL_REQUEST_TITLE
- For builds triggered by
merge-related events
, value is PR title - Otherwise empty string
CNB_PULL_REQUEST_BRANCH
- For builds triggered by
merge-related events
, value is PR source branch name - Otherwise empty string
CNB_PULL_REQUEST_SHA
- For builds triggered by
merge-related events
, value is latest commitsha
of PR source branch - Otherwise empty string
CNB_PULL_REQUEST_TARGET_SHA
- For builds triggered by
merge-related events
, value is latest commitsha
of PR target branch - Otherwise empty string
CNB_PULL_REQUEST_MERGE_SHA
- For builds triggered by
pull_request.merged
, value is mergedsha
- For builds triggered by
pull_request
,pull_request.update
,pull_request.target
,pull_request.mergeable
,pull_request.comment
, value is pre-mergedsha
- Otherwise empty string
CNB_PULL_REQUEST_SLUG
- For builds triggered by
merge-related events
, value is source repository slug, e.g.group_slug/repo_name
,group_slug/sub_gourp_slog/.../repo_name
- Otherwise empty string
CNB_PULL_REQUEST_ACTION
For builds triggered by merge-related events
, possible values:
- created: New PR
- code_update: Source branch push
- status_update: When review approved or CI status changes
PR
becomes mergeable - Otherwise empty string
CNB_PULL_REQUEST_ID
- For builds triggered by
merge-related events
, value is globally uniqueid
of current or relatedPR
- Otherwise empty string
CNB_PULL_REQUEST_IID
- For builds triggered by
merge-related events
, value isiid
number of current or relatedPR
in repository - Otherwise empty string
CNB_PULL_REQUEST_REVIEWERS
- For builds triggered by
merge-related events
, value is reviewer list, multiple separated by,
- Otherwise empty string
CNB_PULL_REQUEST_REVIEW_STATE
For builds triggered by merge-related events
:
- Has reviewers and someone approved, value is
approve
- Has reviewers but no one approved, value is
unapprove
- Otherwise empty string
CNB_REVIEW_REVIEWED_BY
- For builds triggered by
merge-related events
, value is approved reviewer list, multiple separated by,
- Otherwise empty string
CNB_REVIEW_LAST_REVIEWED_BY
- For builds triggered by
merge-related events
, value is last approved reviewer - Otherwise empty string
Workspaces Variables
CNB_VSCODE_WEB_URL
Workspaces address, only exists when services : vscode
is declared
Issue Variables
CNB_ISSUE_ID
- For builds triggered by
issue.*
, value isIssue
globally uniqueID
- Otherwise empty string
CNB_ISSUE_IID
- For builds triggered by
issue.*
, value isIssue
numberiid
in repository - Otherwise empty string
CNB_ISSUE_TITLE
- For builds triggered by
issue.*
, value isIssue
title
- Otherwise empty string
CNB_ISSUE_DESCRIPTION
- For builds triggered by
issue.*
, value isIssue
description
- Otherwise empty string
CNB_ISSUE_OWNER
- For builds triggered by
issue.*
, value isIssue
author username - Otherwise empty string
CNB_ISSUE_STATE
- For builds triggered by
issue.*
, value isIssue
state:open
,closed
- Otherwise empty string
CNB_ISSUE_IS_RESOLVED
- For builds triggered by
issue.*
, indicates whetherIssue
is resolved:true
,false
- Otherwise empty string
Comment Variables
CNB_COMMENT_ID
- For builds triggered by comment events, value is comment globally unique
ID
- Otherwise empty string
CNB_COMMENT_BODY
- For builds triggered by comment events, value is comment content
- Otherwise empty string