Bitbucket Pipelines and git submodules

Hello!

How can I make Pipelines work when my repo contains git submodules that need to be initialized before the build is started?

6 answers

5 votes

you'll need to reconfigure the git remote to pull from Bitbucket. Pipelines uses an O-auth token to do the initial cloning which is then destroyed immediately afterwards.

First you'll want to create an app-password for the user who's going to access the submodules (App passwords are here in Bitbucket Cloud | Bitbucket Blog). This will ensure you can work with 2fa enabled on the account.

Then you'll need to provide the username and app-password as Bitbucket Pipelines variables (https://confluence.atlassian.com/display/BITBUCKET/Environment+variables+in+Bitbucket+Pipelines)

assuming you've named them USERNAME and PASSWORD, add this step to the start of your pipeline:

git remote set-url origin https://$USERNAME:$PASSWORD@bitbucket.org/team/repo.git

followed by initialising your submodules

git submodule update --init

Hi I have tried 20+ times but until the `git submodule update --init` step, it always said:

+ git submodule update --init
Submodule 'dev/scripts/api' (git@bitbucket.org:team/services.git) registered for path 'dev/scripts/api'
Cloning into 'dev/scripts/api'...
Warning: Permanently added 'bitbucket.org' (RSA) to the list of known hosts.

Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:team/services.git' into submodule path 'dev/scripts/api' failed

 

Anyone has experienced this?

 

Did you solve this issue?

 

I'm running into the same problem :(

Please note that, the environment variable $USERNAME mentioned by Sebastian should be account username instead of the app password username. The password should be the password from one of the app passwords you've created in account settings.

It surely is a "massive missing feature in BB Pipelines". After 9 months passing by, is this fixed now? or is it still a manual submodule update?

This seems fixed now with the SSH keys available in pipelines.

 

1. Create an SSH keypair for the repo that runs the pipeline that needs to init a submodule

 

2. Add the public key to the submodule repo.

 

3. add `git submodule update --init` to your pipeline script

Works perfectly! Thanks!

It works. Thanks !

As a note, you should remove 

$USERNAME:$PASSWORD

from your git path in your git commands inside your pipeline script.

Because only the ssh key is enough for authentication. 

That isn't enough.

If your submodules point at an ssh Bitbucket url (git@bitbucket.org:org/repo.git), you need to change the url of the submodule as well. I did it like this:

 

git config --file=.gitmodules submodule.$SUBMODULENAME.url https://$USERNAME:$PASSWORD@bitbucket.org/org/repo.git

Then it's the standard git submodule update --init.

This feels like a massive missing feature in BB Pipelines and I hope it gets resolved in future updates!

Atlassian, this needs urgent fixing! I thought the advantage of using Bitbucket pipelines over some external CI system was the better integration with Bitbucket. Turns out that's not the case. Sad!

0 vote

For anyone else who found this thead and thinks this is a serious oversight, you can vote on the issue here https://bitbucket.org/site/master/issues/12853/private-submodule-support

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

23,629 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you