Private Bitbucket in Pipeline with Cargo

Let's say you have a dependency to a private repo in Cargo.toml such as:

sdl2 = { git = "ssh://" }

and you want to run your tests in the Bitbucket pipeline. You'll get an error:

    Updating index
    Updating git repository `ssh://`
error: failed to load source for a dependency on `cool-sdl2-stuff`
Caused by:
  Unable to update ssh://
Caused by:
  failed to clone into: /home/rust/.cargo/git/db/cool-sdl2-stuff-b9d20094d77d7795
Caused by:
  failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded
Caused by:
  error authenticating: no auth sock variable; class=Ssh (23)

as it turns out, pipelines does add the access keys to the run, but it isn't using the usual ~/.ssh/id_rsa name, so cargo can't find the keys.

The solution is to add this to your step script:

  - eval `ssh-agent -s`
  - ssh-add ~/.ssh/id_pipelines
  - ssh-add -l

And you're good to go.