Bitbucket Pipelines with Maven: Complete Guide
Serving developers since 2016 Founder-run, no venture capital MFA, SSO and audit log on every plan
Every feature on every plan, with unlimited users. 14 days free. No credit card required.
Start free trialIn this guide, we’ll walk through setting up continuous integration using Bitbucket Pipelines with private Maven repositories. This setup allows you to automatically build, test, and deploy your Java artifacts. If you’re new to Maven, our guide to what Maven repositories are covers the fundamentals including repository types and configuration.
Prerequisites
Before we begin, you’ll need:
- Apache Maven installed
- A Bitbucket repository with Pipelines enabled
- A CloudRepo account with a private Maven repository
- Basic understanding of Maven repositories and Git
CloudRepo, JFrog Artifactory and Sonatype Nexus, side by side
| Question | CloudRepo Essentials | JFrog Artifactory Cloud Pro | Sonatype Nexus Pro Cloud |
|---|---|---|---|
| Included each month | 10 GB storage and 250 GB transfer | 25 GB, then $1.25/GB storage and transfer counted together [1] | 25 GB, then $1.10/GB of consumption [2] |
| Users | Unlimited, on every plan | Typically up to 50 users how JFrog sizes Pro [1] | New contracts are priced by consumption [3] |
| Support | Human support, on every plan | Community support: public documentation, a knowledge base and Stack Overflow [4] | Pro lists enterprise support, SLA and migration services as available [2] |
Every feature on every plan
Start free trial Or compare your Sonatype or JFrog quote with ours
14 days free. No credit card required.
Sources (4): each vendor's own pages, read 2026-10-06 to 2026-10-21. Prices as each vendor listed them on the date shown.
- JFrog pricing, read (archived)
- Sonatype pricing, read (archived)
- Sonatype pricing, read
- JFrog pricing, read
(archived)
Community Support - Available for Free solutions and Pro subscriptions - JFrog maintains public documentation, knowledge base, and engages in conversations on Stack Overflow.
Setting Up Your Environment
1. Enable Bitbucket Pipelines
Navigate to your Bitbucket repository settings and enable Pipelines. This will allow you to run automated builds on every push to your repository.
2. Configure Secure Environment Variables
In your Bitbucket repository settings, add these secure environment variables:
CLOUDREPO_USERNAME: the email address of the CloudRepo member the token belongs toCLOUDREPO_API_TOKEN: a repository token, created in the admin portal under Repository Tokens
These variables will be used to authenticate with your private Maven repository without exposing credentials in your code. Revoking a repository token stops that one credential and leaves the rest of the member’s access alone.
Configuration Files
Create bitbucket-pipelines.yml
Add this file to your repository root:
pipelines: branches: master: - step: name: Build and Deploy Snapshot Artifact script: - bash create-settings.sh - mvn -B verify - mvn -B -s settings.xml deploy
release/*: - step: name: Build and Deploy Release Artifact script: - bash create-settings.sh - mvn -B verify - mvn -B -s settings.xml deployConfigure Your POM File
Add distribution management to your pom.xml:
<distributionManagement> <repository> <id>io.cloudrepo.maven.releases</id> <url>https://[your-domain].mycloudrepo.io/repositories/maven-releases</url> </repository> <snapshotRepository> <id>io.cloudrepo.maven.snapshots</id> <url>https://[your-domain].mycloudrepo.io/repositories/maven-snapshots</url> </snapshotRepository></distributionManagement>Create Settings Generator Script
Create create-settings.sh to write Maven’s settings file:
#!/bin/bashcat > settings.xml << 'EOF'<settings> <servers> <server> <id>io.cloudrepo.maven.releases</id> <username>${env.CLOUDREPO_USERNAME}</username> <password>${env.CLOUDREPO_API_TOKEN}</password> </server> <server> <id>io.cloudrepo.maven.snapshots</id> <username>${env.CLOUDREPO_USERNAME}</username> <password>${env.CLOUDREPO_API_TOKEN}</password> </server> </servers></settings>EOFThe quotes around 'EOF' keep the shell from filling in the values. Maven reads ${env.CLOUDREPO_USERNAME} and ${env.CLOUDREPO_API_TOKEN} from the pipeline’s variables when it runs, so the file holds no login.
Deployment Workflow
Snapshot Deployments
Every push to the master branch will:
- Run tests using
mvn verify - Deploy snapshot artifacts to your snapshot repository
- Make artifacts available for other projects immediately
Release Deployments
For release versions:
- Create a release branch (e.g.,
release/1.0.0) - Update version in
pom.xmlto remove-SNAPSHOT - Push to trigger the release pipeline
- Tag the release after successful deployment
Validating Your Setup
Check Pipeline Status
After pushing changes:
- Navigate to Pipelines in your Bitbucket repository
- Monitor the build progress
- Check for any errors in the build logs
Verify Artifacts in CloudRepo
- Log into your CloudRepo account
- Navigate to your repositories
- Confirm artifacts appear in the correct repository (snapshots or releases)
- Verify artifact metadata is correct
Best Practices
Security
- Never commit credentials to your repository
- Use environment variables for sensitive data
- Rotate credentials regularly
- Use repository-specific credentials when possible
Version Management
- Use semantic versioning (MAJOR.MINOR.PATCH)
- Keep snapshot versions on master/develop branches
- Create release branches for stable releases
- Tag releases in Git after successful deployment
Build Optimization
- Cache dependencies to speed up builds
- Run tests in parallel when possible
- Use
-Bflag for non-interactive builds - Consider using build profiles for different environments
Troubleshooting
Common Issues
Authentication Failures
- Verify environment variables are set correctly
- Check credentials haven’t expired
- Ensure repository IDs match between POM and settings
Network Issues
- Verify repository URLs are correct
- Check firewall settings
- Ensure HTTPS is used for secure connections
Build Failures
- Review build logs for specific errors
- Run builds locally to reproduce issues
- Check for dependency conflicts
Advanced Configuration
Multi-Module Projects
For projects with multiple modules:
<modules> <module>core</module> <module>api</module> <module>web</module></modules>Configure each module to inherit distribution management from the parent POM.
Custom Deployment Profiles
Create profiles for different deployment scenarios:
<profiles> <profile> <id>staging</id> <distributionManagement> <!-- Staging repository configuration --> </distributionManagement> </profile></profiles>Conclusion
That’s it: every push builds and publishes to CloudRepo. Try it free for 14 days.
Additional Resources
Every feature on every plan, with unlimited users
14 days free. No credit card required.
Founder-run since 2016, with no venture capital. A real person answers within one business day. Usually it's me.
Chris, founder of CloudRepo