我遇到以下问题:我在GCE(Google Compute Engine)上运行Jenkins,并将其配置为在需要时动态启动代理。主服务器和代理都安装了git,但是路径不同。在主Git上,/opt/bitnami/git/bin/git
上,在Git上的/usr/bin/git
上。
我在Global tool configuration
中配置了两个Git工具,如下所示:
Jenkins文件的相关部分在这里:
pipeline {
agent {
label 'ubuntu-1604'
}
triggers {
pollSCM('H/5 * * * *')
}
tools {
jdk 'JDK11'
git 'agent-git'
}
stages {
stage ('Checkout Source') {
steps {
sh "echo HOSTNAME is: `$hostname`"
checkout scm
}
}
运行此作业时,它失败,因为它对主服务器和代理使用相同的Git路径。我收到以下错误:
Checking out git git@bitbucket.org:my-repo.git into /opt/bitnami/apps/jenkins/jenkins_home/workspace/test-pipeline@script to read Jenkinsfile
using credential XXXXX
Cloning the remote Git repository
Cloning repository git@bitbucket.org:my-repo.git
> /opt/bitnami/git/bin/git init /opt/bitnami/apps/jenkins/jenkins_home/workspace/test-pipeline@script # timeout=10
Fetching upstream changes from git@bitbucket.org:my-repo.git
> /opt/bitnami/git/bin/git --version # timeout=10
using GIT_SSH to set credentials Temporary git credentials using XXXXX's credentials
.....
Fetching upstream changes from git@bitbucket.org:my-repo.git
using GIT_SSH to set credentials Temporary git credentials using XXXXXX's credentials
Checking out Revision b139fca90bb7b66ebb7432fc791bf0b77ef73fbb (refs/remotes/origin/some_branch)
Commit message: "Blah blah blah"
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on ubuntu-1604-agent-d1h0ha in /tmp/workspace/test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential XXXXXX
Cloning the remote Git repository
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /tmp/workspace/test-pipeline
.....
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to ubuntu-1604-agent-d1h0ha
.....
Caused by: hudson.plugins.git.GitException: Error performing git command: /opt/bitnami/git/bin/git init /tmp/workspace/test-pipeline
.....
Caused by: java.io.IOException: Cannot run program "/opt/bitnami/git/bin/git" (in directory "/tmp/workspace/test-pipeline"): error=2, No such file or directory
.....
Caused by: java.io.IOException: error=2, No such file or directory
.....
我尝试了几种修复方法:
Git executable
设置为git-agent
。之所以失败,是因为master上不存在git路径。Lightweight checkout
以及从Jenkinsfile中删除/添加checkout scm
。是否可以为主/代理定义不同的git路径?还是有办法让其中只有一个执行任何git操作?我认为通过取消选中Lightweight checkout
会迫使master进行所有Git操作,相反,我认为在Jenkinsfile中调用checkout scm
会迫使Agent进行所有git操作,但似乎都不是