How to use maven cache for pipelines with dependencies to other bitbucket repos?
Asked by Andreas Schr?ck:

I am currently trying to set up a project which is depending on another project on bitbucket.

I can compile everything with no issue, but I want to optimize the build procedure.

The project that I am depending on is quite large and does not change that often.

I am facing an issue right now: I am cloning the project at one step defined in the pipeline file. This is working but it rebuilds and installs the artifact every time to the local repository, which is not necessary because the same version is already existing.

How can I check if the cache already includes a certain artifact before cloning \& installing the same thing over and over again?


Answers:
author: Patrik S
body: Hello [@Andreas Schr?ck](/t5/user/viewprofilepage/user-id/3626792) ,

Thank you for reaching out to Atlassian Community.

From your description, I understand you are already using [caches](https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/) in your pipeline. What pipeline caches essentially do is zip a given folder and upload it to our infrastructure. On the subsequent runs, this zip will be downloaded and extracted in the same exact location it was generated, but it's up to the framework/tool you are using to make use of this cache.

We provide several pre-defined cache locations for commonly used language tools, as listed in the documentation below :

* <https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/#Pre-defined-caches>

But you can also define custom cache locations if your application is looking at different folders :

* <https://support.atlassian.com/bitbucket-cloud/docs/cache-dependencies/#Custom-caches-for-other-build-tools-and-directories>

As you mentioned you are cloning another huge dependency repository that does not change often, another option is for you to build your own custom docker image that already includes that dependency, and use that image in the steps that need the dependency. Since the image will already contain the repository, you will not need to clone it every time you do your build :

* <https://support.atlassian.com/bitbucket-cloud/docs/use-docker-images-as-build-environments/#Custom-build-environments>

Hope that helps! Let me know in case you have any questions.

Thank you, [@Andreas Schr?ck](/t5/user/viewprofilepage/user-id/3626792) .

Kind regards,

Patrik S

comments: author: Andreas Schr?ck
body: Thx for the links!

The docker image must be on docker hub, correct?


author: Patrik S
body: Hello [@Andreas Schr?ck](/t5/user/viewprofilepage/user-id/3626792) ,

We support public and private Docker images including those hosted on Docker Hub, AWS, GCP, Azure and self-hosted registries accessible on the internet, so it's up to your choice where you better prefer to host your image :)

Kind regards,

Patrik S


author: Andreas Schr?ck
body: Thx!

Is there any documentation available on how to use Azure?


author: Patrik S
body: Hello [@Andreas Schr?ck](/t5/user/viewprofilepage/user-id/3626792) ,

There's no specific documentation on how to use Azure, but the following example is for private registries and should apply to Azure Container Registry (ACR) as well :

```
image: 
  name: myregistry.azurecr.io/samples/my_image 
  username: $USERNAME 
  password: $PASSWORD
```

You can find more details on ACR in Microsoft's documentation below :

* <https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli?tabs=azure-cli>

Thank you, [@Andreas Schr?ck](/t5/user/viewprofilepage/user-id/3626792) .

Patrik S


Tags: bitbucket-cloud

bitbucket-pipelines

cloud

maven