Creating a Bitbucket Pipeline

Malshani Wijekoon
3 min readOct 27, 2023

--

What is Bitbucket? Bitbucket is a web-based platform for version control and collaboration primarily used by software development teams. It provides a set of tools for managing and organizing source code, collaborating with team members, and automating various aspects of the software development workflow. Bitbucket is developed and maintained by Atlassian.

What is Bitbucket Pipeline? Bitbucket Pipelines is a continuous integration and continuous deployment (CI/CD) service offered by Bitbucket, a web-based platform for version control and collaboration. Bitbucket Pipelines is designed to automate and streamline the software development and delivery process by providing a set of features for building, testing, and deploying code changes directly from Bitbucket repositories.

In this article I’m going to explain the process of setting up bitbucket pipeline. To configure a pipeline you need to have a bitbucket account with a project (repository).

First you commit all your code to repository.

Create a Pipeline. Go to pipeline -> Click ‘Create’

Select ‘Build a Maven Project’

Add following code to ‘bitbucket-pipelines.yml’ file.

#  Template maven-build

# This template allows you to test and build your Java project with Maven.
# The workflow allows running tests, code checkstyle and security scans on the default branch.

# Prerequisites: pom.xml and appropriate project structure should exist in the repository.

image: maven:3.9.2

pipelines:
default:
- parallel:
- step:
name: Build and Test
caches:
- maven
script:
- mvn clean install -DskipTests --file pom.xml
after-script:
# Collect checkstyle results, if any, and convert to Bitbucket Code Insights.
- pipe: atlassian/checkstyle-report:0.3.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.5.1

This is a basic yml file. If you want you can add extra tasks to yml file. As an example if you want to add sonarqube scan, simply you can add it by clicking sonar cloud scan option in configurations (See below image).

Commit the file. As soon as you commit the file, pipeline will start running.

By clicking on the status you can see the pipeline log.

You may edit the ‘bitbucket-pipelines.yml’ file as per your desire.

--

--