How to use git submodule init property?

Aharono August 15, 2021

I have a submodule in my git (private repository, located in bitbucket as well) and I want to load it in the pipelines but I get the error:

fatal: could not read Username for 'https://bitbucket.org': No such device or address

Now, obviously, the error occurs because I didn't set user and password and my question is how can I do it properly assuming that we use with our submodules

Thanks 

 

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 23, 2021

Hi @Aharono,

If you want to use HTTPS, you can create and use repository variables for the username and password. I strongly recommend generating an app password for your Bitbucket account with permissions "Repositories : Read" only, and use that app password instead of your account's password.

After you generate the app password, open in Bitbucket website the repo that has the submodule. Select Repository settings > Repository variables and create one variable for your Bitbucket username and another one for the app password.

Please make sure that the variable for the app password is marked as Secured, so that its value won't appear in the Pipelines log. You can also make the username variable Secured if you don't want your username to be visible in the Pipelines log.

Let's say the variables are named BB_username and BB_password. Then, in your bitbucket-pipelines.yml file you can add the following commands:

- git config submodule.<my-submodule>.url https://${BB_username}:${BB_password}@bitbucket.org/<workspace-id>/<submodule-repo>.git
- git submodule init
- git submodule update

where
<my-submodule> replace with the name of the submodule, as defined in the .gitmodules file
<workspace-id> replace with the workspace id that owns the submodule
<submodule-repo> replace with the repo slug for the submodule repo

 

Please keep in mind though that even secured variables can be retrieved by all users with write access to a repository. If other users have write access to these two repos and you'd like to avoid that, another option would be to use SSH instead of HTTPS.

In order to set this up, open in Bitbucket website the repo that has the submodule. Select Repository settings > SSH keys and then select Generate keys to generate an SSH key pair for Pipelines in this repo. Then, copy the public key.

Open the submodule repository on Bitbucket website, go to its Repository settings > Access keys and add there the public SSH key you copied before.

Afterwards, you can use the following commands in your yml file:

- git config submodule.<my-submodule>.url git@bitbucket.org:<workspace-id>/<submodule-repo>.git
- git submodule init
- git submodule update

Make the same replacements in the 'git config' command as I mentioned earlier.

Please feel free to let me know if this works for you and if you have any questions.

Kind regards,
Theodora

mostafakamal January 17, 2023

For me, it works perfectly. Thanks :)

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 17, 2023

That's good to hear, you are very welcome @mostafakamal

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events