git - Jenkins 代理和主服务器上的 Git 路径不同
问题描述
我有以下问题:我在 GCE(谷歌计算引擎)上运行 Jenkins,它被配置为在需要时动态启动代理。主服务器和代理服务器都安装了 git,但路径不同。在主服务器上,Git 位于/opt/bitnami/git/bin/git
和代理上/usr/bin/git
。
我配置了两个 Git 工具,Global tool configuration
如下所示:
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
- 我不能做这样的事情,因为我的节点是动态的。
有没有办法为主/代理定义不同的 git 路径?或者有没有办法让其中一个执行任何 git 操作?我认为取消选中Lightweight checkout
会强制 master 执行所有 Git 操作,相反我认为调用checkout scm
Jenkinsfile 会强制代理执行所有 git 操作,但似乎都不是这样。
解决方案
推荐阅读
- angularjs - DevExpress - 如果另一个单元格具有值,如何禁用一个单元格的编辑
- android - 错误代码 413:您的客户端发出的请求在 WEB VIEW 中太大
- substrate - 在 Polkadot 应用程序开发人员选项卡中,您如何编码 Rust 元组?
- python-3.x - 使用给定 url、代理和用户凭据的 python 下载文件的代码
- scala - 测试中*的含义是什么?
- javascript - 如何在Javascript中复制包含数组的表单元素?
- regex - 如何创建一个将正则表达式与括号匹配的函数
- sql - SSMS - SQL - 有未提交的事务。你想在关闭窗口之前提交这些吗?
- java-8 - Jetty Http2 服务器不适用于 Java 8
- javascript - 数据处理 JS 到 PHP 插入 SQL 数据库