【发布时间】:2019-12-10 19:07:02
【问题描述】:
我有以下问题:我在 GCE(Google Compute Engine)上运行 Jenkins,它被配置为在需要时动态启动代理。主服务器和代理服务器都安装了 git,但路径不同。在主 Git 上位于 /opt/bitnami/git/bin/git,在代理上位于 /usr/bin/git。
我在Global tool configuration中配置了两个Git工具,如下图:
Jenkinsfile的相关部分在这里:
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
}
}
当我运行这个作业时,它失败了,因为它为 master 和 agent 使用了相同的 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 路径。 - 我能想到的所有组合都可以从 Jenkinsfile 中选中/取消选中
Lightweight checkout以及删除/添加checkout scm。 - 我无法执行this 之类的操作,因为我的节点是动态的。
有什么方法可以为 master/agents 定义不同的 git 路径?或者有没有办法让其中一个执行任何 git 操作?我认为取消选中 Lightweight checkout 会强制 master 执行所有 Git 操作,相反我认为在 Jenkinsfile 中调用 checkout scm 会强制代理执行所有 git 操作,但似乎都不是这样。
【问题讨论】:
-
为什么不使用
install automatically设置? -
它不需要安装在任何地方,两台机器都已经安装了git。我确实尝试检查
install automatically只是为了测试它并且遇到了同样的问题 -
我现在可以通过为 git 路径设置一个硬链接来让它工作,即
ln /opt/bitnami/git/bin/git /usr/bin/git,但这感觉不是一个好的解决方案,所以我把它留在希望通过 Jenkins/code 解决方案 -
有没有可能不支持
git工具? -
@wearebob,谢谢。顺便说一句,我可以通过进入 Jenkins 节点部分在 Windows 代理的工具部分下指定 git 位置来解决此问题。
标签: git jenkins jenkins-pipeline