I have the following problem: I am running Jenkins on GCE (Google Compute Engine) and it is configured to start up agents dynamically when needed. The master and agents both have git installed, but at different paths. On the master Git is located at /opt/bitnami/git/bin/git
and on the agent at /usr/bin/git
.
I have two Git tools configured in Global tool configuration
as shown below:
My pipeline job is setup as below:
The relevant part of the Jenkinsfile here:
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
}
}
When I run this job, it fails because it uses the same Git path for both master and the agent. I get the following error:
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
.....
I have tried several fixes:
- Set the
Git executable
in the job togit-agent
. This fails because the git path does not exist on master. - All combinations I can think of checking/unchecking
Lightweight checkout
and removing/addingcheckout scm
from the Jenkinsfile. - I cannot do something like this because my nodes are dynamic.
Is there any way to define different git paths for master/agents? Or is there a way to have only one of them perform any git operations? I thought by unchecking Lightweight checkout
that would force master to do all Git operations, conversely I thought calling checkout scm
in the Jenkinsfile would force the agent to do all git operations, but neither of those seem to be the case.