2

I already had a look at this question, but I wonder how I can securely download a single from a private Git repository in a declarative pipeline, preferably using a credentials ID or similar.

I assume I have to use something like:

sh 'git archive ... || tar --extract'
beatngu13
  • 7,201
  • 6
  • 37
  • 66

1 Answers1

1

for this purpose there is a ssh agent plugin that can be used within the pipeline script:

sshagent(credentials: ['credentials-id']) {
  sh "git archive --remote=${git_repository_url} --format=tar ${branch_name} ${path_to_file} | tar xf -"
}

Note: path_to_file can be either the path to a file, or just the filename

Snailedlt
  • 460
  • 6
  • 14
Niko
  • 333
  • 3
  • 10
  • Somehow my credentials ID doesn't work with the `sshagent` step, whereas it works fine when I perform a clone with the [`git`](https://jenkins.io/doc/pipeline/steps/git/) step. Also, when I use the snippet generator, I see the correct credentials ID in the dropdown menu of the Git plugin, but not in the SSH Agent plugin. Any ideas? (BTW: Would you mind adding a [link to the plugin](https://jenkins.io/doc/pipeline/steps/ssh-agent/)?) – beatngu13 Jun 16 '18 at 09:11