首页 > 解决方案 > 在声明性 Jenkins 管道中从私有 Git 存储库下载单个文件

问题描述

我已经看过这个问题,但我想知道如何在声明性管道中安全地从私有 Git 存储库下载一个,最好使用凭证 ID 或类似的。

我想我必须使用类似的东西:

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

标签: gitjenkinsjenkins-pipeline

解决方案


为此,可以在管道脚本中使用 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 -"
}

推荐阅读