从声明性Jenkins管道中的私有Git存储库下载单个文件

时间:2018-06-15 13:56:04

标签: git jenkins jenkins-pipeline

我已经查看了this question,但我想知道如何从声明性管道中的私有Git存储库中安全地下载单个,最好使用凭据ID或类似的。

我认为我必须使用类似的东西:

sh 'git archive ... || tar --extract'

1 个答案:

答案 0 :(得分:1)

为此目的,有一个ssh代理插件可以在管道脚本中使用:

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 -"
}
相关问题