Can I use git command in delivery pipeline if git is installed in different path on jenkins agent than on master

1k Views Asked by At

I have the following scenario.

I tried a simple pipeline job that clones my remote repo. It works fine when i set it to execute on master.

node {
   //stage 'Checkout'
     git([url: 'ssh://[email protected]:29418/bla/bla.git', branch: 'mybranch'])
}

It uses the default git installation to run the command. I have configured git on a different pat for slave in jenkins configuration. when i try to run the same pipeline on a slave, it fails because it always tries to go the default git installation.

node ('myagent1'){
   //stage 'Checkout'
     git([url: 'ssh://[email protected]:29418/bla/bla.git', branch: 'mybranch'])
}

The error is obvious:

Caused by: hudson.plugins.git.GitException: Error performing command: /jenkins-master-some-path/bin/git init /home/user/workspace/pipeline

/jenkins-master-some-path/bin/git is correct for master.

For normal jobs, we can choose one installation but can someone tell me if there is a way to use different git installation for pipeline on a slave.

2

There are 2 best solutions below

1
On BEST ANSWER

Another solution, that will work with all the tools, is to configure specific tools installations path for your specific agent node.

Go to :

Jenkins > Manage Nodes > myagent1 > nodes properties > tools 

... and then select the tool that cannot be found on your agent (e.g. Git executable) and just fill there your executable path.

0
On

Ohhh I found a way. Instead of using git command, i used this "checkout" module. From pipeline job configuration, if you click on "pipeline Syntax", it takes you to another page. There you can generate groovy just by using the GUI.