【问题标题】:Jenkins groovy pipeline - git checkout errorJenkins groovy 管道 - git checkout 错误
【发布时间】:2016-11-03 12:26:50
【问题描述】:

我已经使用 Groovy DSL 定义了一个简单的 Jenkins 管道。我的意图是它会简单地检查我的 git 存储库。但是我遇到了一个错误。

鉴于我的 groovy DSL 定义:

stage 'build'
node 
{
    git branch: '*/mybranch', credentialsId: 'my credentials', url: 'git@git.servername:pathto/myrepo.git'
}

我希望 Jenkins 管道能够简单地检查我的 git 存储库。

但是我收到以下错误:

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE

谁能帮我解决这个问题?

【问题讨论】:

  • 管道记录结帐期间执行的所有特定 git 命令。我会调查那些寻找答案的人,首先比较“短”和“完整”输出。很难向您提出更好的建议,因为您的问题依赖于特定的 git 存储库设置,因此无法重现

标签: jenkins groovy jenkins-pipeline


【解决方案1】:

更详细的版本有效:

checkout([$class: 'GitSCM', branches: [[name: '*/mybranch']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'myCredentials', url: 'git@git.servername:pathto/myrepo.git']]])

不过最好使用速记版本。

【讨论】:

  • 感谢您发布您的解决方案。这个更详细的版本对我有用。使用简写,它只是说[Pipeline] tool,然后继续下一步,从不克隆回购。但是对于详细版本,我看到[Pipeline] checkout Cloning the remote Git repository 等。
【解决方案2】:

没有 */ 分支说明符对我有用。

试试这个:

git branch: 'mybranch', credentialsId: 'my credentials', url: 'git@git.servername:pathto/myrepo.git'

【讨论】:

  • 感谢您的回答卢克。我已经离开了这个项目,所以我无法轻松验证,但也许这对其他人有帮助。虽然,我感觉我的问题在于我的 git repo 设置而不是 Jenkins。