Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Cache Tools in Bitbucket Pipelines for Ubuntu 20.04 Builds

홍창기 March 6, 2024

I'm using Bitbucket Pipelines and I have a question about it.

I want to build my repository on Ubuntu 20.04. The essential tools I need are as follows:

  • gcc 9, g++ 9
  • cmake
  • openjdk8, openjdk17, openjre17
  • ant

I am currently installing all the software each time I build using the following command:

apt-get update && apt-get install -y gcc-9 g++-9 cmake openjdk-8-jdk openjdk-17-jre openjdk-17-jdk ant

This is inefficient.

I want to know how to cache the tools I've installed once. How should I write my bitbucket-pipelines.yml?

Below is part of my yml file

image: atlassian/default-image:latest

pipelines:
  default:
    - step:
        name: Build on Ubuntu 20.04
        image: ubuntu:20.04
        script:
          - apt-get update && apt-get install -y gcc-9 g++-9 cmake openjdk-8-jdk openjdk-17-jre openjdk-17-jdk ant

2 answers

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 8, 2024

Hi @홍창기 and welcome to the community!

The recommended approach for your use case is to create a custom Docker image with the tools you need and use that as a build environment instead of ubuntu:20.04.

If you install Docker on your computer, you can build an image from a Dockerfile like the following:

FROM ubuntu:20.04
RUN apt-get update && apt-get install -y gcc-9 g++-9 cmake openjdk-8-jdk openjdk-17-jre openjdk-17-jdk ant

You can then create an account and a repo in Dockerhub and push the image you build to this repo. If the repo's name is e.g. myaccount/myimage:latest, then you can use that in your yml file's step instead of ubuntu:20.04.

It is not necessary to use Dockerhub, you could also use another Docker registry. We support public and private Docker images including those hosted on Docker Hub, AWS, GCP, Azure, and self-hosted registries accessible on the internet.

You can find more details here:

There is a section with the title Creating a custom build environment near the end of this page with more resources.

Please feel free to reach out if you have any questions.

Kind regards,
Theodora

홍창기 March 17, 2024

@Theodora Boudale Thank you. I going to try this. Have a good day

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2024

You are very welcome @홍창기, please feel free to let me know if you encounter any issues.

Have a nice day too!

Like Sabine Mayer likes this
1 vote
Aron Gombas _Midori_
Community Champion
March 7, 2024

It is possible to cache Docker images and many other artifacts:

https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events