I have a Jenkins controller machine that runs Windows and an agent machine that runs on MacOS. Both machines have git installed.
If I type where git
in my Mac's terminal, I get this output: /usr/bin/git
.
My goal is: I'm trying to check out the 'team-ci' repo into the workspace of the Pipeline Project.
The issue is that if I do it using
git branch: 'main',
credentialsId: "defaultssh",
url: "git@global.com:team/team-ci.git"
, then it tries to check out the 'main' branch using the Windows executable, so instead, I opted out for the checkout
method.
Here's what the "Git installations" in "Global Tool Configuration" look like:
I wrote this pipeline code:
pipeline {
agent {
label 'mac1'
}
stages {
stage('Execute') {
steps {
script {
def branch = '*/main'
def credentialsId = 'defaultssh'
def projectUrl = "git@global.company.gitlab.com:team/team-ci.git"
def gitTool = isUnix() ? 'git_mac' : 'git_win'
echo "gitTool: " + gitTool
checkout([$class: 'GitSCM', branches: [[name: branch]],
gitTool: gitTool,
userRemoteConfigs: [[credentialsId: credentialsId, url: projectUrl]]
])
}
}
}
}
}
When I try to run this Pipeline Project, it outputs these exceptions in the console:
13:14:19 gitTool: git_mac
13:14:19 [Pipeline] checkout
13:14:19 The recommended git tool is: NONE
13:14:19 using credential defaultssh
13:14:19 Cloning the remote Git repository
13:14:19 ERROR: Error cloning remote repo 'origin'
13:14:19 hudson.plugins.git.GitException: Could not init /Library/Automation/jenkins/workspace/mac_pipeline_project
13:14:19 Caused by: hudson.plugins.git.GitException: Error performing git command: /usr/bin/git init /Library/Automation/jenkins/workspace/mac_pipeline_project
13:14:19 Caused by: java.io.IOException: Cannot run program "/Library/Automation/jenkins/workspace/" (in directory "/Library/Automation/jenkins/workspace/mac_pipeline_project"): error=13, Permission denied
13:35:19 Caused by: java.io.IOException: error=13, Permission denied
13:35:20 ERROR: Error cloning remote repo 'origin'
What can I do to successfully clone the 'team-ci' project?
I had to go to the Dashboard/Manage Jenkins/Nodes/mac1 and change the "Tool locations" value from "/Library/Automation/jenkins/workspace/" to "/usr/bin/git" under the "(Git) git_mac" tool.