I'm looking for ways to validate my pipelines will run before sending them to PR. Is there a simple way to write tests for the bitbucket-pipeline.yml file?
For example a pipeline that builds and deploys a react app, I would want to run the build step, verify the build files are there then ftp to a mocked location, or maybe just somewhere on my local machine.
I am aware of the validator tool, but it still feels like a bit of a shot in the dark whether my pipeline will run successfully or not and I'm burning through PRs.
Hi @Max Mycroft. The validator only checks the file's structure, so it can't tell you whether the build or the FTP step will actually run. That's the gap you're hitting. Atlassian doesn't offer a way to execute a whole bitbucket-pipelines.yml locally as-is. What works is reproducing a single step by hand. Pull the same image your step declares, mount your repo, and run the script lines yourself:
docker run -it --volume=$(pwd):/app --workdir=/app node:20 /bin/bash
Swap node:20 for your step's image. Inside there you run your build, confirm the artifacts are present, and point the FTP at a local folder (or a throwaway ftp container) rather than the real host. Atlassian documents this at https://support.atlassian.com/bitbucket-cloud/kb/debug-pipelines-locally-with-docker/
On the PRs, you don't need one to trigger a build. Push to a throwaway branch and the pipeline runs there, then delete the branch. You get the real runner's result without opening a PR.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.