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

dl5txlt9  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(126)

我已经看过了this question,但我想知道如何在声明性管道中安全地从私有Git仓库下载一个single,最好使用凭证ID或类似的信息。
我假设我必须使用类似于以下内容的内容:

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

emeijp431#

为此,存在可在管道脚本内使用的ssh代理插件:

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

注意:path_to_file可以是文件的路径,也可以只是文件名

相关问题