Wondering if anyone has figured a clever way of doing this, but after drone has cloned the repo, I want to perform a lookup of all remote branches to perform a cleanup step on development environments. However, I cannot query the remote git repo because the container does not use drone api keys to query the private repo. I was thinking I’ll create a read-only key that gets mounted into the container to use, but maybe there is a oob solution?
Have you tried something like
git ls-remote --heads origin?
$ git ls-remote --heads origin 91a347bf9eea950fe352058bdefe5a038e0356a2 refs/heads/master 01daadea962630a3778caa725ce0880771a9ff64 refs/heads/some-feature
I cannot query the remote git repo because the container does not use […] api keys to query the private repo
I’m not sure this is entirely true because if your repository is private, drone automatically create a
.netrc file which is used by the git client to automatically authenticate remote git requests using git+https. That is how Drone is able to clone a repository and then clone dependencies store in version control (e.g. go get). Note that this capability has been in place since 0.5.
You’re totally right. I’m still not certain what I had been doing incorrectly before, but things are working as expected and I can query the remote private repo. Thanks for clearing that up!
I think this is more a netrc issue, but doesn’t look like I can run a script that sources netrc. Running straight commands under drone like so, works.
remote: image: alpine commands: - apk add -U git - "git ls-remote --heads origin"
git ls-remote --heads origin from a script and calling the script from
/root/.netrc get: line 1: /root/.netrc: not found. The script starts off with
git config --global credential.helper "$HOME/.netrc"
This will not work because the
.netrc file is not the same thing as a credential helper file; they are different formats. The netrc is automatically used by libcurl, which is what git uses for git+https requests. No additional configuration or commands required.
Ah. I feel this should just work then. I built an example repo to show the problem. The first test, like you said, calling the command
git ls-remote --heads origin works. This can be seen in
test1 step of .drone.yml.
test2 shows running the same command called from a script, baked into an image, but fails.
The .netrc file is automatically created for command steps (e.g. steps with the commands section). In your example
test2 is effectively a plugin, which means the plugin is responsible for creating the netrc file (for reference, this is what the git plugin does https://github.com/drone-plugins/drone-git/blob/master/utils.go#L44:L62)
Oh cool! I’ll try to reproduce that in some form or fashion. Thanks for your help!
We have a shell version of the git plugin, which you can use for reference https://github.com/drone-plugins/drone-git/blob/next/posix/clone#L8
Flippin sweet! That was precisely what I needed. Thanks again!