How to specify Jenkins agent git address from Jenkins controller in Jenkins pipeline script?

5.2k views Asked by At

I am trying to use Jenkins controller/agent architecture for my maven project. I have Jenkins controller on Windows and Jenkins agent on Linux. Now the problem is when I run my Jenkins script it gives me an error like unable to init git repositories because Jenkins is trying to execute git.exe on Linux agent machine. can anyone let me know that how can I resolve it?

following is my Jenkins pipeline script and error log

node ('lx-dotoolsd1')
{
    stage 'Checkout'
    git branch: 'main', credentialsId: 'ee44e971-4cce-4e59-95b6-
    da222007775b', url: ' http://o-heena@bitbucket:7990/scm/phoen/audit-
    confirmation.git'
    stage 'Test'
    def pom = readMavenPom file: 'pom.xml'
    print "Build: " + pom.version
    env.POM_VERSION = pom.version
    //batch 'mvn clean compile install'
    //junit '**/target/surefire-reports/TEST-*.xml'
    currentBuild.description = "v${pom.version} (${env.branch})"
}

error is as following

Started by user Patel,Heena
[Pipeline] node
Running on lx-dotoolsd1 in /var/jenkins/workspace/pipelineTest
[Pipeline] {
[Pipeline] stage (Checkout)
Entering stage Checkout
Proceeding
[Pipeline] git
Cloning the remote Git repository
Cloning repository http://o-heena@bitbucket:7990/scm/phoen/audit-confirmation.git
> git.exe init /var/jenkins/workspace/pipelineTest # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /var/jenkins/workspace/pipelineTest
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:656)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:463)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:152)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:145)
at hudson.remoting.UserRequest.perform(UserRequest.java:152)
at hudson.remoting.UserRequest.perform(UserRequest.java:50)
at hudson.remoting.Request$2.run(Request.java:332)
1

There are 1 answers

0
ANIL On

This issue is occurring as your Linux Node is accessing the Git path from the Global Tool Configuration.

Since, your master machine is Windows the Git path points to Git.exe.

I think that you haven't set the Git path for your slave machine.

Go to http://<JENKINS_URL>/computer/<NODE_NAME>/configure, this will take you to your slave configuration page. There under Node Properties check Tool Location and from List of Tool Location select Git and add the GIT_HOME path of the Git that is installed in your slave machine there.

enter image description here