Bitbucket Pipelines: a variable is empty
Pipelines has several kinds of variables, and each one reaches only some places. When a step prints nothing for a variable, or a command acts as if it were not set, it is usually one of the cases below.
A deployment variable, outside its deployment step
Deployment variables belong to an environment. You set them in Repository settings, Deployments, under the environment, and they override repository and workspace variables with the same name (Atlassian's Set up and monitor deployments). A step gets them by naming that environment in deployment:
pipelines:
branches:
main:
- step:
deployment: production
script:
- echo "API URL: $API_URL" # production's value
A step without deployment, or with another environment, does not see production's values. Atlassian's Variables and secrets gives the order when names collide: pipeline, then deployment, then repository, then workspace.
To see the command that got an empty variable: Pipeline Inbox for Bitbucket Pipelines, a plugin for JetBrains IDEs, points, in the pipelines of all your Bitbucket Cloud repositories, to the failed step and the command it stopped at.
A secured variable is hidden, not empty
A secured variable (the padlock) is masked in the log, and so is any output that matches its value. In Atlassian's example, echo "Deploying with key $API_KEY" shows $API_KEY in the log, not the key. To see whether a value arrived without printing it, print its length:
- echo "API_KEY has ${#API_KEY} characters"
A secured variable cannot be edited, only replaced or deleted.
A variable exported in an earlier step
Each step runs in a new container, so export ends with the step. Atlassian's Variable sharing passes a value on: write KEY=VALUE to the file in $BITBUCKET_PIPELINES_VARIABLES_PATH and list the name under output-variables.
- step:
name: Generate version
script:
- export VERSION=$(date +%Y%m%d)-$BITBUCKET_BUILD_NUMBER
- echo "VERSION=$VERSION" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
output-variables:
- VERSION
- step:
name: Deploy
script:
- echo "Deploying $VERSION"
- List every name the step writes under
output-variables. For a name written to the file but not listed, Atlassian's troubleshooting gives the error "Variable not defined in output variables". - A pipeline can share 50 variables and 100 KB in total. The limit is checked twice: when the YAML is read, the
output-variableslists of all steps together can't name more than 50 ("This pipeline contains more than the maximum 50 output variables allowed"), and while the pipeline runs, the stored values can't go over 50 variables or 100 KB. - The values reach every step that starts after the writing step finishes, including the steps after a parallel group. The steps of one parallel group usually start together, so don't count on a sibling's variables, and give each output variable a name of its own within the group. Until its update of November 6, 2026, Atlassian's page said a variable written in a parallel step reached no other step.
- A value from
output-variableswins over a workspace, repository or deployment variable of the same name, and over a variable entered when running a custom pipeline. Some built-in variables, such asBITBUCKET_PIPELINES_VARIABLES_PATH, can't be overridden. - A child pipeline, started by a
type: pipelinestep, gets them only when that step passes them underinput-variables, as inAPP_VERSION: $VERSION.
Files go between steps as artifacts.
$VAR outside the script
$VAR is filled in by the shell when a script line runs. In other fields, such as image, a step's name, deployment or a cache path, use ${{VAR}}. Atlassian added it in May 2025 (the announcement), and YAML templating (updated November 6, 2026) says it is a plain text replacement over the whole file, done before the file is read as YAML and before any step runs. So it works anywhere in the file, script lines included, and in files brought in with import:, which take the variables of the repository running the pipeline.
image: ${{NODE_IMAGE}} # a repository variable, for example node:20
- It takes non-secured workspace and repository variables, and the default variables that are known before the pipeline starts:
BITBUCKET_WORKSPACE,BITBUCKET_REPO_SLUG,BITBUCKET_BRANCH,BITBUCKET_COMMITandBITBUCKET_PR_ID, and others such asBITBUCKET_TAG,BITBUCKET_REPO_UUID,BITBUCKET_PROJECT_KEYandBITBUCKET_PR_DESTINATION_BRANCH. Each exists only where it applies:BITBUCKET_PR_IDin pull request pipelines,BITBUCKET_TAGin tag pipelines. - Secured variables, deployment variables and variables shared through
output-variablesare not available at that point. - No spaces inside the braces:
${{ VARIABLE_NAME }}, as GitHub Actions writes it, is not filled in. Names are letters, digits and underscores, and the case counts. - A name it cannot fill in, a variable with an empty value included, stays in the file as it is,
${{VARIABLE_NAME}}. The file is still read; the pipeline or step fails later where the text is used, and in a script line that is a "bad substitution" error. There is no fallback syntax, so define the variable with a value that isn't empty. The page says to check that it is a workspace or repository variable, not secured, and spelled the same, case included.
The exception is the build image's credentials: Atlassian's examples write username: $DOCKER_HUB_USERNAME and password: $DOCKER_HUB_PASSWORD under image.
Names, and default variables that only some builds have
- Names are case-sensitive, use letters, digits and underscores, and cannot start with a digit.
BITBUCKET_BRANCHis set in branch builds,BITBUCKET_TAGin tag builds andBITBUCKET_PR_IDin pull request builds. A tag build has no branch name.BITBUCKET_PARALLEL_STEPandBITBUCKET_PARALLEL_STEP_COUNTexist only inside a parallel step.- A variable called
PATHreplaces the build's own and breaks commands ("command not found"). - The variables of a build together are limited to 120,000 characters ("Step exceeded processing limits").
Bitbucket Pipelines in IntelliJ IDEA
Pipeline Inbox for Bitbucket Pipelines, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, lists the pipelines of all your Bitbucket Cloud repositories in an IDE tool window, with their steps, the failed step and the command it stopped at, and the step's log as Bitbucket writes it. The list, steps and logs are free; running, re-running and stopping pipelines are Pro (US$1.50 a month, with a 30-day trial). Running a custom pipeline gives a field for each variable it declares.
Get it on JetBrains Marketplace
Atlassian, Bitbucket and Bitbucket Pipelines are trademarks of Atlassian; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by Atlassian or JetBrains.
More: "Host key verification failed" (SSH) · "Cannot connect to the Docker daemon" · "authorization denied by plugin pipelines" (Docker) · "Container 'docker' exceeded memory limit." · Pipelines did not run after a push · "Container 'Build' exceeded memory limit." · "Exceeded build time limit of 120 minutes" · The cache is not used · "unexpected system error" · "command not found" · Submodules not cloned · "We couldn't clone the repository" · "No online runner available" · "No space left on device" · "Step exceeded processing limits" · The artifact is missing in the next step · The build passed before and fails now · Build setup takes too long · "You've run out of build minutes" · "Permission denied to update branch" · "You have reached your pull rate limit" (Docker Hub) · "There is an error in your bitbucket-pipelines.yml" · "This pipeline was paused" (deployments) · Test results not showing · "Not authorized to perform sts:AssumeRoleWithWebIdentity" (OIDC to AWS) · "Connection refused" to a service (MySQL, PostgreSQL, Redis) · "Container 'build' failed to pull image" · The scheduled pipeline did not run · Git commands that fail in a shallow clone (origin/main, git describe) · Git LFS files that arrive as pointers, and LFS pushes from a step · A step skipped by condition: changesets (includePaths) · Parallel steps that keep running after one fails (fail-fast) · Bitbucket Pipelines plugins for IntelliJ IDEA, compared · 日本語