Caching Yum Packages in Bitbucket Pipelines for Faster Builds

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

When installing packages in a Linux distribution-based server, the package manager recognizes if a package is already installed, displaying a "Already installed" message. Similarly, in Bitbucket Pipelines, caching packages can speed up builds. This document guides you through caching Yum packages in pipeline builds.

Environment

Bitbucket Cloud

Solution

Yum downloads the .rpm files when we install any packages. These rpm files are stored in /var/lib. 

The path differs based on the OS distribution of the base image. In this KB, the OS distribution used is Amazon Linux. 

Configure the /var/lib folder as a cache in the pipeline build to avoid downloading a package if it's already installed.

Sample bitbucket-pipelines.yml:

1 2 3 4 5 6 7 8 9 10 11 12 definitions: caches: yum-cache: /var/lib pipelines: branches: **: - step: image: <image name> script: - yum install openssh-clients -y caches: - yum-cache

Updated on March 3, 2025

Still need help?

The Atlassian Community is here for you.