### Install AWS CLI and jq Source: https://support.atlassian.com/bitbucket-cloud/docs/deploy-to-amazon-ecs This example demonstrates how to install the AWS CLI and the `jq` utility within a Debian-based environment. This is a prerequisite for using the AWS CLI method to deploy to ECS. ```bash - apt-get update && apt-get install -y jq - curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" - unzip awscli-bundle.zip - ./awscli-bundle/install -b ~/bin/aws - export PATH=~/bin:$PATH ``` -------------------------------- ### Complete bitbucket-pipelines.yml Example Source: https://support.atlassian.com/bitbucket-cloud/docs/deploy-to-kubernetes This snippet shows a full `bitbucket-pipelines.yml` configuration for a CI/CD pipeline. It includes steps for installing dependencies, running tests, building a Docker image, authenticating with Docker Hub, pushing the image, and deploying to Kubernetes. ```yaml pipelines: default: - step: name: Test script: - npm install - npm test - step: name: Build script: - export IMAGE_NAME=$DOCKER_HUB_USERNAME/$APPLICATION_NAME:$BITBUCKET_COMMIT # build the Docker image (this will use the Dockerfile in the root of the repo) - docker build -t $IMAGE_NAME . # authenticate with the Docker Hub registry - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD # push the new Docker image to the Docker registry - docker push $IMAGE_NAME services: - docker - step: name: Deploy deployment: production script: - sed -i "s|{{image}}|$DOCKER_HUB_USERNAME/$APPLICATION_NAME:$BITBUCKET_COMMIT|g" deployment.yml - pipe: atlassian/kubectl-run:1.1.2 variables: KUBE_CONFIG: $KUBE_CONFIG KUBECTL_COMMAND: 'apply' RESOURCE_PATH: 'deployment.yml' ``` -------------------------------- ### Install Docker CLI via Dockerfile Source: https://support.atlassian.com/bitbucket-cloud/docs/enable-and-use-runtime-v3 Example of multi-stage Dockerfile to copy the Docker CLI, buildx plugin, and docker-compose into a custom build image. ```dockerfile FROM docker:28.1.1-cli AS docker-cli FROM ubuntu:24.04 # Copy Docker CLI, Buildx plugin and docker-compose COPY --from=docker-cli /usr/local/bin/docker /usr/local/bin/docker COPY --from=docker-cli /usr/local/libexec/docker/cli-plugins/docker-buildx /usr/local/libexec/docker/cli-plugins/docker-buildx COPY --from=docker-cli /usr/local/bin/docker-compose /usr/local/bin/docker-compose ``` -------------------------------- ### Running a Hello World Build in Jenkins and Bitbucket Pipelines Source: https://support.atlassian.com/bitbucket-cloud/docs/how-to-migrate-from-jenkins-to-bitbucket-pipelines This snippet demonstrates the basic 'Hello World' command execution in both Jenkins using Groovy syntax and Bitbucket Pipelines using YAML. It's a fundamental example for starting with CI/CD. ```groovy pipeline { agent any stages { stage('Example') { steps { echo 'Hello World' } } } } ``` ```yaml image: atlassian/default-image:4 pipelines: default: - step: name: Example script: - echo 'Hello World' ``` -------------------------------- ### Full Bitbucket Pipelines Example for JUnit/TestNG Source: https://support.atlassian.com/bitbucket-cloud/docs/quarantining-flaky-tests A complete Bitbucket Pipelines step that injects test metadata, installs `jq`, parses quarantined tests for Maven, and skips them during the build. ```yaml pipelines: default: - step: name: Skip quarantined Tests image: maven:3.8.4-openjdk-11 test-management: inject-classification: true script: - apt-get update && apt-get install -y jq - QUARANTINED_TESTS=$(jq -r '.quarantinedTests[] | "!\(.class)#\(.name)"' "$BITBUCKET_TEST_METADATA_FILE_PATH" | paste -sd "," -) - mvn clean install -Dtest="$QUARANTINED_TESTS" ``` -------------------------------- ### Verify Docker Installation in Pipelines Source: https://support.atlassian.com/bitbucket-cloud/docs/run-docker-commands-in-bitbucket-pipelines A pipeline configuration example that runs the 'docker version' command to verify that the Docker daemon is correctly accessible. ```yaml pipelines: default: - step: script: - docker version services: - docker ``` -------------------------------- ### Manage Dependencies with Composer Source: https://support.atlassian.com/bitbucket-cloud/docs/php-with-bitbucket-pipelines Installs project dependencies using Composer. This example adds 'monolog/monolog' and runs 'composer install'. It also includes system package installations required for some PHP extensions. ```yaml image: php:7.1.1 pipelines: default: - step: script: - apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - composer require monolog/monolog - composer install ``` -------------------------------- ### Windows Runner Installation Commands Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket Execute these PowerShell commands on your Windows host machine to download, unzip, and start the runner software. The token authenticates the host with Bitbucket. Save these commands securely as they are only displayed once. ```powershell Invoke-WebRequest -Uri https://bitbucket.org/atlassian/bitbucket-runner/downloads/bitbucket-runner-windows-amd64.zip -OutFile bitbucket-runner-windows-amd64.zip Expand-Archive -Path bitbucket-runner-windows-amd64.zip -DestinationPath . .itbucket-runner.exe install --token YOUR_TOKEN ``` -------------------------------- ### Linux Runner Installation Command Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket Use this Docker command on your runner host machine to download and start the necessary software for Linux runners. The token authenticates the host with Bitbucket. ```bash docker run --rm -e BITBUCKET_TOKEN="YOUR_TOKEN" -v /opt/atlassian/runners:/opt/atlassian/runners atlassian/bitbucket-runner:latest ``` -------------------------------- ### Install Maven Dependencies Source: https://support.atlassian.com/bitbucket-cloud/docs/working-with-the-apache-maven-registry Run the `gradle build` command to install the defined dependencies. ```bash gradle build ``` -------------------------------- ### Install Maven dependencies using mvn install Source: https://support.atlassian.com/bitbucket-cloud/docs/working-with-the-apache-maven-registry Execute this command to install the dependencies defined in your `pom.xml`, including those from the Bitbucket registry. ```bash mvn install ``` -------------------------------- ### Manage Dependencies with Pear Source: https://support.atlassian.com/bitbucket-cloud/docs/php-with-bitbucket-pipelines Installs PHP extensions using the Pear package manager. This example installs the PHP_CodeSniffer package. ```yaml image: php:7.1.1 pipelines: default: - step: script: - pear -V - pear install pear/PHP_CodeSniffer ``` -------------------------------- ### Deploy Artifacts using bitbucket-upload-file pipe Source: https://support.atlassian.com/bitbucket-cloud/docs/deploy-build-artifacts-to-bitbucket-downloads This example demonstrates how to create a Go application, build it, and then upload the compiled binary to Bitbucket Downloads using the bitbucket-upload-file pipe. Ensure the bitbucket-pipelines.yml file is placed at the root of your repository. ```yaml image: golang:1.25.0 pipelines: default: - step: name: Create hello world go app artifacts: - main.go script: - | cat > main.go << 'EOF' package main func main() { println("Hello, World!") } EOF - step: name: Build artifacts: - compiled_app script: - go build -o compiled_app main.go - step: name: Upload script: - pipe: atlassian/bitbucket-upload-file:0.7.5 variables: ATLASSIAN_ACCOUNT_EMAIL: $ATLASSIAN_ACCOUNT_EMAIL ATLASSIAN_API_TOKEN: $ATLASSIAN_API_TOKEN FILENAME: "compiled_app" ``` -------------------------------- ### Initialize and Connect Repository Source: https://support.atlassian.com/bitbucket-cloud/docs/git-and-mercurial-commands Commands to set up a new local Git repository and link it to a remote server. Use these to start version control in a local directory. ```bash git init git remote add origin ``` -------------------------------- ### Get User Information Source: https://support.atlassian.com/bitbucket-cloud/docs/oauth-endpoints Example of a cURL request to retrieve user information and the corresponding JSON response. ```bash $ curl https://api.bitbucket.org/2.0/users/tutorials ``` ```json { "username": "tutorials", "nickname": "tutorials", "account_status": "active", "website": "https://tutorials.bitbucket.org/", "display_name": "tutorials account", "uuid": "{c788b2da-b7a2-404c-9e26-d3f077557007}", "links": { "self": { "href": "https://api.bitbucket.org/2.0/users/tutorials" }, "repositories": { "href": "https://api.bitbucket.org/2.0/repositories/tutorials" }, "html": { "href": "https://bitbucket.org/tutorials" }, "followers": { "href": "https://api.bitbucket.org/2.0/users/tutorials/followers" }, "avatar": { "href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png" }, "following": { "href": "https://api.bitbucket.org/2.0/users/tutorials/following" } }, "created_on": "2011-12-20T16:34:07.132459+00:00", "location": "Santa Monica, CA", "type": "user" } ``` -------------------------------- ### Glob Pattern Matching Condition Source: https://support.atlassian.com/bitbucket-cloud/docs/pipeline-start-conditions Example of using the glob() function to match branches starting with 'feature/'. ```APIDOC ## Glob Pattern Matching Condition ### Description Runs for any branch starting with "feature/". ### Condition ``` condition: glob(BITBUCKET_BRANCH, "feature/*") ``` ``` -------------------------------- ### Stage and Commit Workflow Example Source: https://support.atlassian.com/bitbucket-cloud/docs/add-edit-and-commit-to-source-files A practical example demonstrating the sequence of staging all changes, verifying the status of the repository, and committing those changes with a descriptive message. ```bash git add --all git status git commit -m 'Initial commit of all files to the repository' ``` -------------------------------- ### Configure PHPUnit Test Reporting Source: https://support.atlassian.com/bitbucket-cloud/docs/test-reporting-in-pipelines Example bitbucket-pipelines.yml configuration to install PHPUnit and generate JUnit-compatible XML reports. ```yaml image: php:7.1.1 pipelines: default: - step: script: - apt-get update && apt-get install -y unzip - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - composer require phpunit/phpunit - vendor/bin/phpunit --log-junit ./test-reports/junit.xml ``` -------------------------------- ### Installing Dependencies in Bitbucket Pipelines Source: https://support.atlassian.com/bitbucket-cloud/docs/debug-pipelines-locally-with-docker This example demonstrates how to install Python packages, like SciPy, using pip within a `python:3` container in Bitbucket Pipelines. It's essential for ensuring your project has the necessary libraries before execution. ```yaml # You can use a Docker image from Docker Hub or your own container # registry for your build environment. image: python:3 pipelines: default: - step: script: # Modify the commands below to build your repository. - python --version - python myScript.py - pip install scipy ``` -------------------------------- ### Install Ruby Dependencies Source: https://support.atlassian.com/bitbucket-cloud/docs/ruby-with-bitbucket-pipelines Demonstrates how to install project dependencies using Bundler or the gem command within the pipeline execution script. ```yaml image: ruby:2.4.0 pipelines: default: - step: script: - bundle install ``` ```yaml image: ruby:2.4.0 pipelines: default: - step: script: - gem install rails ``` -------------------------------- ### macOS Runner Installation Command Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket This command installs the Bitbucket Pipelines runner on a macOS host. It downloads, unzips, and starts the software, using the provided token for Bitbucket authentication. This command is displayed only once, so ensure it is stored securely. ```bash curl -Ls https://bitbucket.org/atlassian/bitbucket-pipelines-runner/downloads/runner-macos.zip -o runner.zip; unzip runner.zip -d . ; ./runner --url https://bitbucket.org --access-key YOUR_ACCESS_KEY --runner-uuid YOUR_RUNNER_UUID ``` -------------------------------- ### Build, Test, and Deploy Workflow Comparison Source: https://support.atlassian.com/bitbucket-cloud/docs/how-to-migrate-from-bamboo-to-bitbucket-pipelines This snippet shows the equivalent configurations for a build, test, and deploy workflow in Bamboo and Bitbucket Pipelines, highlighting artifact handling and deployment steps. ```yaml version: 2 plan: project-key: PROJ key: PLAN name: Example Plan stages: - Lint and Test: - Lint - Build Artifact: - Build Artifact - Publish Image: - Publish Image Lint: tasks: - script: - npm install - npm lint docker: image: node:alpine Build Artifact: tasks: - script: - ${bamboo_capability_system_builder_npm} install - ${bamboo_capability_system_builder_npm} run build - script: - cp -r content build/ - cp release/* build/ requirements: - node artifacts: - name: release pattern: build/** Deploy Image: tasks: - artifact-download: source-plan: PROJ-PLAN artifacts: - name: release ``` ```yaml image: atlassian/default-image:5 pipelines: default: - step: name: Lint and Test caches: - node script: - npm install - npm lint - npm test - step: name: Build Artifact script: - npm install - npm run build - cp -r content build/ - cp release/* build/ - zip -r build.zip build/ artifacts: - build.zip - step: name: Deploy Image services: - docker script: - pipe: atlassian/aws-code-deploy:1.5.0 variables: AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION S3_BUCKET: $S3_BUCKET COMMAND: "upload" APPLICATION_NAME: "my-application" ZIP_FILE: "build.zip" ``` -------------------------------- ### Configure Opsgenie and Slack Pipes with Variables Source: https://support.atlassian.com/bitbucket-cloud/docs/step-options Example demonstrating the configuration of Opsgenie Send Alert and Slack Notify pipes using defined variables. This is a repeat of the first example but explicitly linked to the 'Pipe variables' section. ```yaml pipelines: default: - step: name: Alert everyone! script: - pipe: atlassian/opsgenie-send-alert:latest name: Send alert to Opsgenie variables: GENIE_KEY: $GENIE_KEY MESSAGE: 'Wake up!' - pipe: atlassian/slack-notify:latest name: Send alert to Slack variables: WEBHOOK_URL: $SLACK_WEBHOOK PRETEXT: 'Alert Everyone!' MESSAGE: 'We have a problem!' ``` -------------------------------- ### Linux Shell Runner Installation Command Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket This Bash command installs the Bitbucket Pipelines runner on a Linux host using a shell script. It downloads, unzips, and starts the necessary software. The provided token authenticates the host with Bitbucket. Securely store this command as it is only shown once. ```bash curl -Ls https://bitbucket.org/atlassian/bitbucket-pipelines-runner/downloads/runner-linux-amd64.tar.gz | tar xz -C /tmp && sudo mv /tmp/runner /usr/local/bin/runner && sudo runner --url https://bitbucket.org --access-key YOUR_ACCESS_KEY --runner-uuid YOUR_RUNNER_UUID ``` -------------------------------- ### Example bitbucket-pipelines.yml Configuration Source: https://support.atlassian.com/bitbucket-cloud/docs/debug-pipelines-locally-with-docker A sample `bitbucket-pipelines.yml` file demonstrating the use of a Docker image (e.g., from Docker Hub) for the build environment and defining default pipeline steps. This configuration includes running basic commands like checking the Python version and executing a Python script. ```yaml # You can use a Docker image from Docker Hub or your own container # registry for your build environment. image: python:3 pipelines: default: - step: script: # Modify the commands below to build your repository. - python --version - python myScript.py ``` -------------------------------- ### Checking Python Version Source: https://support.atlassian.com/bitbucket-cloud/docs/debug-pipelines-locally-with-docker This command checks the installed Python version within the container. It's a fundamental step to ensure compatibility and correct environment setup. ```bash python --version ``` -------------------------------- ### Jenkinsfile Example Source: https://support.atlassian.com/bitbucket-cloud/docs/how-to-migrate-from-jenkins-to-bitbucket-pipelines A sample Jenkinsfile showcasing pipeline structure with different agents for stages, including Docker images for Maven and Node.js. ```groovy pipeline { agent { docker { image 'alpine:3.20' } } stages { stage('Back-end') { agent { docker { image 'maven:3.9.9-eclipse-temurin-21-alpine' } } steps { sh 'mvn --version' } } stage('Front-end') { agent { docker { image 'node:20.18.0-alpine3.20' } } steps { sh 'node --version' } } } } ``` -------------------------------- ### Full Bitbucket Pipelines Example for Pytest Source: https://support.atlassian.com/bitbucket-cloud/docs/quarantining-flaky-tests A complete Bitbucket Pipelines step that injects test metadata, installs `jq`, parses quarantined tests for Pytest, and skips them during the build. ```yaml pipelines: default: - step: name: Skip Quarantined Tests test-management: inject-classification: true script: - apt-get update && apt-get install -y jq - QUARANTINED_TESTS=$(jq -r '.quarantinedTests[] | "not \(.class)::\(.name)"' "$BITBUCKET_TEST_METADATA_FILE_PATH" | paste -sd " and " -) - python3 -m pytest -k $QUARANTINED_TESTS -v ``` -------------------------------- ### Install Dependencies with npm or Yarn Source: https://support.atlassian.com/bitbucket-cloud/docs/javascript-nodejs-with-bitbucket-pipelines Demonstrates how to install project dependencies using either npm or Yarn within a pipeline step. These commands assume a package.json file exists in the repository root. ```yaml image: node:22.15.0 pipelines: default: - step: script: - npm install ``` ```yaml image: node:22.15.0 pipelines: default: - step: script: - yarn ``` -------------------------------- ### List Issues on a Repository Source: https://support.atlassian.com/bitbucket-cloud/docs/oauth-endpoints This example shows how to list all issues on a specific Bitbucket tutorial repository using the 2.0 API. ```APIDOC ## GET /2.0/repositories/{repo_owner}/{repo_name}/issues ### Description Retrieves a list of issues for a given repository. ### Method GET ### Endpoint https://api.bitbucket.org/2.0/repositories/{repo_owner}/{repo_name}/issues ### Parameters #### Path Parameters - **repo_owner** (string) - Required - The username or team name of the repository owner. - **repo_name** (string) - Required - The name of the repository. ### Response #### Success Response (200) - **issues** (array) - A list of issue objects. - **issue** (object) - Represents an issue with various fields like title, status, author, etc. ``` -------------------------------- ### Dockerfile for Node.js Application Source: https://support.atlassian.com/bitbucket-cloud/docs/deploy-to-kubernetes This Dockerfile defines the environment for a Node.js application. It sets up the working directory, installs dependencies, copies application source code, and specifies the command to start the application. ```dockerfile FROM node:boron # Create app directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Install app dependencies COPY package.json /usr/src/app/ RUN npm install # Bundle app source COPY . /usr/src/app/ EXPOSE 8080 CMD [ "npm", "start" ] ``` -------------------------------- ### Configure Docker Registry Login and Buildx Source: https://support.atlassian.com/bitbucket-cloud/docs/enable-and-use-runtime-v3 Demonstrates how to authenticate with Docker Hub and initialize a buildx builder to avoid rate limits during pipeline execution. ```yaml options: runtime: cloud: version: "3" pipelines: custom: docker-hub-login: - step: script: - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - docker buildx create --name mybuilder --driver docker-container --use - docker buildx build -t myimage:latest . ``` -------------------------------- ### Configure Runtime for All Steps Source: https://support.atlassian.com/bitbucket-cloud/docs/step-options Configure runtime options like 'atlassian-ip-ranges' and 'arch' for all steps within a pipeline. This example enables IP ranges for 4x, 8x, and 16x steps, and sets the architecture to 'arm' for all steps. ```yaml options: runtime: cloud: atlassian-ip-ranges: true arch: arm pipelines: default: - step: size: 4x script: - echo "I use atlassian-ip-ranges" ``` -------------------------------- ### Windows Runner Installation Command Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket This PowerShell command is used to download, unzip, and start the Bitbucket Pipelines runner software on a Windows host. The token in the command authenticates the host with Bitbucket. Store this command securely as it is only displayed once. ```powershell Invoke-WebRequest -Uri https://bitbucket.org/atlassian/bitbucket-pipelines-runner/downloads/runner-windows-amd64.zip -OutFile runner.zip; Expand-Archive -Path runner.zip -DestinationPath .; . unner.exe --url https://bitbucket.org --access-key YOUR_ACCESS_KEY --runner-uuid YOUR_RUNNER_UUID ``` -------------------------------- ### Linux Docker Runner Installation Command Source: https://support.atlassian.com/bitbucket-cloud/docs/adding-a-new-runner-in-bitbucket Use this Docker command to download and start the Bitbucket Pipelines runner software on a Linux host. The token authenticates the host with Bitbucket. The command defaults to the latest runner image version. ```bash docker run -d --restart always -v /opt/atlassian/pipelines/runner:/opt/atlassian/pipelines/runner -e RUNNER_UUID=YOUR_RUNNER_UUID -e ACCESS_KEY=YOUR_ACCESS_KEY atlassian/bitbucket-pipelines-runner:latest ``` -------------------------------- ### Dockerfile Configuration for Containerizing Scripts Source: https://support.atlassian.com/bitbucket-cloud/docs/write-a-pipe-for-bitbucket-pipelines Defines the structure and content of a Docker container. It specifies the base image, copies necessary files into the container, and sets the entrypoint script to run when the container starts. This example uses Alpine Linux and Bash. ```dockerfile FROM alpine:3.8 RUN apk update && apk add bash COPY pipe / ENTRYPOINT ["/pipe.sh"] ``` -------------------------------- ### Start Linux Docker Runner with Proxy Configuration Source: https://support.atlassian.com/bitbucket-cloud/docs/configure-a-runner-to-use-a-proxy This command demonstrates how to initialize a Bitbucket runner container while injecting proxy environment variables to ensure connectivity for git operations and REST API calls. ```bash docker container run \ -e HTTP_PROXY="http://my-http-proxy" \ -e HTTPS_PROXY="http://my-https-proxy" \ docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner ``` -------------------------------- ### Install npm dependency using npm Source: https://support.atlassian.com/bitbucket-cloud/docs/working-with-the-npm-registry Run this command to install all dependencies listed in your `package.json`, including packages from the Bitbucket registry. ```bash npm install ``` -------------------------------- ### Build Bitbucket Pipelines Importer with Maven Source: https://support.atlassian.com/bitbucket-cloud/docs/how-to-migrate-from-jenkins-to-bitbucket-pipelines Instructions for building the Bitbucket Pipelines Importer tool from source code using Apache Maven. Includes cloning the repository, navigating into the directory, building the package, and running the tool. ```bash git clone https://bitbucket.org/bitbucketpipelines/bitbucket-pipelines-importer/src/main/ ``` ```bash cd bitbucket-pipelines-importer ``` ```bash mvn package spring-boot:repackage ``` ```bash java -jar target/bitbucket-pipelines-importer-0.0.3.jar --help ```