Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clone a git repo jus once

Marcus December 7, 2021

For now the bitbucket pipeline clones the repo in every step.

But is there a way of just cloning once and sharing the repo files like a cache?

Or do we have to make the repo as an artifact after cloning?

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 9, 2021

Hello Marcus,

Welcome to Atlassian Community!

Just to give you a little background, Pipelines uses a server-less infrastructure, meaning that the build containers are only provisioned on demand. When your pipeline build starts, it starts a docker container with the image that you provide on the YML file, and run the script commands that you have configured. The build setup includes the following steps :

  • Pull the docker images used by that step
  • Execute a git clone operation to copy the content of the repository
  • Download cache and artifacts if available.

That being said, since every build step runs in a separate docker container, each time a step starts it will clone the repository by default.

At this moment, if you want to use the repo folder in next steps but don't want to clone it again, the only option is by creating an artifact of the repository directory, as you mentioned.

You can also use the following alternatives to improve your build :

  • Reduce the clone depth of your repository in case you don't need older commit:
    clone:
      depth: 5       # include the last five commits, for example  
    pipelines:
      default:
        - step:
            name: Cloning
            script:
              - echo "Clone just five commits!"
  • If there are steps on your pipeline where you are not using the repository, you can disable the repository clone by using the following YML flag :
    - step:
            clone: 
              enabled: false
            script:
              - echo "test"

Hope that helps to address your questions! :)

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events