Bitbucket Pipelines: How to pass values between steps for CI/CD
In Bitbucket pipelines, steps function as isolated execution units that perform tasks like running compilers or tests. However, a key challenge arises: steps cannot access outputs from previous steps because each rebuilds the working directory from scratch.
This problem is illustrated when "Build 2" cannot access a file created by "Build 1", resulting in an error when attempting to read importantfile.txt.
Solution: Using Artifacts
The solution involves leveraging the artifacts property. By declaring files as artifacts in one step, subsequent steps can access them automatically:
artifacts:
- importantfile.txt
This allows downstream steps to retrieve and use the file. The approach extends to directories as well using glob patterns like tests/**.
Practical Applications
Artifacts enable passing:
- Environment files (.env)
- Generated directories
- Temporary data between execution units
For example, a tests directory containing multiple test result files can flow through the pipeline seamlessly.
Key Takeaway
Now every step will first download artifacts from previous steps that you can use in the pipeline to complete your work.
This mechanism solves CI/CD workflows requiring data sharing across sequential pipeline stages without manual workarounds.
For more details, see the Atlassian Bitbucket documentation.