Drone

How to set multiple credentials in Drone server to fetch different private repositories?

Hi,

Just started setting up a Drone pipeline for a GoLang project (Go version 1.12.x). It has one module that depends on a private github repo, and another module that depends on a private bitbucket repo.

Which is the best way to set up credentials for both of them at the server so that I don’t have to add additional commands in Drone’s YAML ?

Thanks!

register the same SSH key with GitHub and Bitbucket and store the SSH key as a repository secret. Then can use the same SSH key in Drone to clone both repositories.

steps:
- name: deps
  image: alpine/git
  environment:
    SSH_KEY:
      from_secret: ssh_key
  commands:
  - mkdir $HOME/.ssh
  - echo "$SSH_KEY" > $HOME/.ssh/id_rsa
  - chmod 600 $HOME/.ssh/id_rsa
  - git clone git@bitbucket.org...
  - git clone git@github.com...

Thanks for the response, Ash! However, from what I know, go mod download or go get <MODULE> uses HTTP(S) while using git internally. Locally, if I have to run the tasks manually, a .netrc file comes in handy and is often the preferred approach. Is there a way to go about it in Drone, you’d reckon ? Thanks again!

the solution for netrc would be similar, but instead of an ssh key, you would store the netrc as a secret and write to disk:

steps:
- name: deps
  image: golang
  environment:
    NETRC:
      from_secret: NETRC
  commands:
  - echo "$NETRC" > $HOME/.netrc
  - chmod 600 $HOME/.netrc
  - go install ./...

Oh cool, makes sense. Thanks mate!