Deploying git submodules in Bitbucket Pipelines

Git submodules makes it easy have repos for common dependencies, but how to actually clone them in your Bitbucket Pipeline?

Bitbucket Pipelines is a great deployment tool tightly integrated into Bitbucket. It allows you to trigger deployments directly from repository branches and tags, and you can customize your deployment steps as needed.

One missing feature in Pipelines is that it is not able to automatically clone submodules that are added to your repository as this requires some additional settings. Until this feature gets added by default, there is a simple way to achieve this.

First, we need to make sure our repository has access to clone the sub-modules repository. You can configure this by reading Cloning another Bitbucket repository in Bitbucket Pipelines.

Next, the git submodule update --init --recursive command can initialize, fetch and checkout any nested submodules. Add it to the beginning of the script block.

pipelines:
  default:
    - step:
        script:
          - git submodule update --init --recursive

The above Pipeline checks out all nested submodules during its execution. We can then use them in subsequent build steps.

Deploying git submodules in Bitbucket Pipelines
Enlarge — Deploying git submodules in Bitbucket Pipelines

Resources

BITBUCKET PIPELINES series

  1. Automating AWS Lambda deployments using Bitbucket Pipelines and Bitbucket Pipes
  2. Automating Serverless framework deployments using Bitbucket Pipelines
  3. Exporting Bitucket repositories and Pipelines with Python
  4. Automating Amazon Elastic Container (ECR) container builds using Bitbucket Pipelines
  5. Deploying git submodules in Bitbucket Pipelines
  6. Cloning another Bitbucket repository in Bitbucket Pipelines
  7. Replicating Bitbucket Pipelines on your laptop for local debugging
  8. ← previous post
    Cloning another Bitbucket repository in Bitbucket Pipelines

    next post →
    Replicating Bitbucket Pipelines on your laptop for local debugging

    86TechnologyView source