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
  • 4,966
  • 4
  • 33
  • 57

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_the_file/filename or only the filename} | tar xf -"
}
Niko
  • 323
  • 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