How to clone a private git repo from within a BitBake recipe?

13,852

Solution 1

As stated in another comment, you can also use git+ssh:

SRC_URI = "git://[email protected]/path/to/repo;protocol=ssh"

Then you need to add the public key of the user that runs bitbake to the git server. A good way of debugging why a fetch does not work is to actually use ssh -v to connect:

ssh -v [email protected]

Beware of weird path differences between git server implementations (like GitLab), for instance, we need to use something like this (note the tilde) to make these URI work from both Bitbake and Google Repo:

SRC_URI = "git://[email protected]:~/groupname/repo.git;protocol=ssh;branch=${BRANCH}"

Solution 2

Well, maybe not the answer you're looking for...

Usually, I'm using ssh-authentications, and thus I just use the username in the SRC_URI; then ssh-agent takes care of the authenticaton part. This can rather easily also be set up on an autobuilder.

Another approach would be to add the credentials to .netrc. In this case, add a file .netrc to you home directory, with contents as follows:

machine stash1.mycompany.com
login myusername 
password mypassword

This should allow you to omit the username and password from SRC_URI.

Depending on you situation, it might be considered a benefit to not store the credentials in the recipe itself. Or it might not...

If you want to store the password (with the ')') in your recipe, you'll need to find a way to escape it, or maybe surround it with "'". (This is completely untested, and I haven't got a password protected git repository to play around with).

Share:
13,852
karobar
Author by

karobar

Been a eukaryote for the last 30 or so years and I think I might be starting to get the hang of it. Experience: Extrauterine Human from 1991-present 31 weeks as a Fetus 840 hours as an Embryo 120 hours as a Blastocyst 96 hours as a Zygote 20 hours as a Morula When I'm not breathing or moving, you might be able to find me thinking about sexual reproduction, eating, or drinking. Favorite planet: Earth Favorite temperature: 22°C Favorite pressure: Somewhere around 101 kPa

Updated on July 17, 2022

Comments

  • karobar
    karobar almost 2 years

    I'm interested in cloning contents of a private git repo so they can be used by a custom BitBake recipe. I've tried adapting this technique from the Yocto Project mailing lists, and produced the following:

    SRC_URI = "git://www.example.com/path/to/repo;protocol=https;branch=master;name=commit;user=<username>:<password>
    SRCREV_commit = "9f8309bbdf0632191bec21fada2cb61a30bcf53e"
    

    The password I'm using contains a left parentheses. I get this error:

    /bin/sh: -c: line 0: syntax error near unexpected token `)'
    

    Can I escape this special character in some way or perhaps use some other way to clone the repo?