[SOLVED] Can i use plugins/git to clone another repo?

Hi!

Case: i’ve got repo A and repo B
When i commit to repo A i’d like to clone repo B too, same branch, to repo A workspace.

Is it possible via plugins/git?

Or should i simply setup some kludge git + secret + etc + etc to clone the other repo manually?

Thanks a bunch in advance!

Ok, i have found this one, so passing remote is not an option.

http://discuss.harness.io/t/how-do-i-correctly-specify-a-custom-drone-remote-url-on-clone-step-in-my-drone-yml/484

The git clone plugin cannot be used in a generic way to clone other repositories. If you want to clone additional repositories, you can add a clone step to your pipeline commands:

pipeline:
  deps:
    image: docker:git
    commands:
      - git clone https://git.company.com/foo/bar.git
      - git clone https://git.company.com/foo/baz.git

Note that you do not need to use secrets here. If your main repository is private, drone will automatically create a netrc file in your containers which git will use by default to automatically authenticate when cloning. Note that you must use the git+http clone urls for this to work.

Additional references:

1 Like

Thats awesome!! Thank you!
Couldn’t yet get it working, got private repo in bitbucket, and additional repo also there.

  deps:
    image: docker:git
    commands:
      - git clone git@bitbucket.org:someteam/some-repo.git

yields:

+ git clone git@bitbucket.org:someteam/some-repo.git
Cloning into 'some-repo'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

https links are not ok in bitbucket, they contain username in them, and they failed also anyway.

+ git clone https://myname@bitbucket.org/someteam/some-repo.git
Cloning into 'some-repo'...
fatal: could not read Password for 'https://myname@bitbucket.org': No such device or address

Any ideas?

Ok i’ve added sleep 90 to commands and went there to take a look.

/drone/src/bitbucket.org/someteam/somearepo # cat ~/.netrc 
machine bitbucket.org
login x-token-auth
password lTkDhIx7EQ-and-so-on

and

/drone/src/bitbucket.org/someteam/somerepo # git clone git@bitbucket.org:someteam/some-repo.git
Cloning into 'some-repo'...
The authenticity of host 'bitbucket.org (104.192.143.2)' can't be established.
RSA key fingerprint is SHA256:zzXQOXSRBEiUtuE8AikJYKwb-bla-bla.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org,104.192.143.2' (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.

You are using the git+ssh url when you need to be using the git+http url.

    commands:
-     - git clone git@bitbucket.org:someteam/some-repo.git
+     - git clone https://bitbucket.org/someteam/some-repo.git

If you have hard-coded git+ssh links into your repository you can try to override at runtime using global git configuration options:

git config --global url."https://bitbucket.org/".insteadOf git@bitbucket.org:

I do something like this in one of my private repositories and can confirm it works without issue. However, if for some reason you cannot get it working, you can always fallback to an ssh key stored in a secret. I do this too in one of my projects, see this example.

1 Like

Purely awesome, sorry for my dumbness, working perfectly =)! Yay!