【发布时间】:2018-10-31 10:58:16
【问题描述】:
我在脚本化的 Jenkins 管道中有一个 sh 步骤,该步骤反过来要求 git 通过 SSH 克隆一个私有 GitHub 存储库(它是一个依赖管理系统,用于处理托管在 GitHub 上的依赖项)。管道本身通过 GitHub 组织插件执行。它包括一个checkout scm 命令,该命令还访问一个私有存储库,从日志中我看到它利用GIT_SSH 环境变量将登录信息传递给该步骤(工作正常)。有没有办法将相同的信息也传递给另一个步骤,即我的sh "install_dependencies.sh" 步骤?请注意,withCredentials 可以让我通过环境变量访问凭据,但是如何将它们传递给 git? GIT_SSH 是 ssh 包装脚本的路径,我不知道如何使用 withCredentials 生成它。还有另一种通过环境变量将凭据传递给 git 的方法吗?
最小的Jenkinsfile 如下所示:
node {
checkout scm // successfully accesses github credentials
withCredentials([
// what to put here?
]) {
// install python dependencies
sh 'pip install -r requirements.txt'
}
sh 'pytest'
}
文件requirements.txt 列出了依赖关系,它包含一行表格
-e git+ssh://git@github.com/some_private/repo@dev#egg=egg_name
它指示pip 通过git 获取需求。
可能可以使用另一个 Jenkins checkout scm 步骤手动签出代码,然后从 Jenkinsfile 中安装它。但是,这会破坏将 requirements.txt 作为需求的唯一真实来源的目的。
【问题讨论】:
-
你是说你的
requirements.txt有依赖被git拉入吗?我不知道pip能做到这一点。
标签: git jenkins github ssh jenkins-pipeline