我目前正在 Jenkins 中自动化一个项目。我正在使用一个从源代码管理工具(在我的例子中为 GIT(读取和执行 Jenkinsfile 的管道。为此,我提供 git URL 并提供带有"Jenkins 凭据提供程序"的凭据并执行构建。它读取 Jenkinsfile 并签出代码,但在下一阶段失败:
pipeline{
agent any
stages{
...
stage('Cloning GIT Repo'){
steps{
echo 'Cloning the repository'
git url: 'http://test.git'
}
}
...
它给出错误:
No credentials specified
我有办法使用我之前在 Jenkins UI 中指定的全局凭据吗?
您可以使用credentialsId
参数
git(
url: 'http://test.git',
credentialsId: 'jenkins-credentials',
branch: "${branch}"
)
https://jenkins.io/doc/book/pipeline/jenkinsfile/#optional-step-arguments https://jenkins.io/doc/pipeline/examples/#push-git-repo