Issue
I'm fairly new to Jenkins but I'm trying to set up a Multi OS Agent environment. Jenkins Master is on Windows Server 2019, and I have a separate Windows Server 2019 agent (Laconia) and an Ubuntu 20.04 agent (Java8Europa) both successfully connected via SSH. I've also configured Git on both instances and I have created two Git tool locations in the global tools config as shown below and confirmed that these work on the individual machines.
The problem I have is that even if I set the individual nodes to use the correct Git tool as shown below, if I try to execute a simple declarative pipeline job, it will only ever use the Git instance which is at the top of the list above (WindowsGit). My declarative pipeline starts with a Windows Script which executes correctly but then when it tries to execute the Linux shell script on the Linux box, it fails as it attempts to use WindowsGit.
I'll include the console log output below, but is there anyway how I can force via the Jenkinsfile which git tool should be used per agent? I did read that there are some tool locations which are ignored by the agents and there are some articles which suggest Git is one of these and the fact that if I switch the order of the Git installations to have the LinuxGit at the top, the pipeline fails to run the Windows script which would seem to support those articles. Any other way I can get around this?
[Pipeline] withEnv
[Pipeline] {
[Pipeline] bat
administrator@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>hello.bat
administrator@LACONIA C:\Jenkins\WorkingRepo\workspace\ReidacusOrg_siplogscanner_main@2>echo "This is coming from a Windows Script"
"This is coming from a Windows Script"
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Say Hello)
[Pipeline] node
Running on Java8(Europa) in /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
[Pipeline] {
[Pipeline] checkout
using credential GitHubAPIAccess
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:997)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:752)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:376)
at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to Java8(Europa)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1800)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
at hudson.remoting.Channel.call(Channel.java:1001)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
at jdk.internal.reflect.GeneratedMethodAccessor882.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
at com.sun.proxy.$Proxy96.execute(Unknown Source)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1221)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1299)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:125)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:93)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:80)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: hudson.plugins.git.GitException: Error performing git command: "C:\Git\bin\git.exe" init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2457)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2380)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2376)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1923)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:995)
... 11 more
Caused by: java.io.IOException: Cannot run program ""C:\Git\bin\git.exe"" (in directory "/home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
at hudson.Launcher$ProcStarter.start(Launcher.java:508)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2443)
... 15 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 20 more
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Say Bye)
Stage "Say Bye" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Cloning repository https://github.com/reidacus/siplogscanner.git
"C:\Git\bin\git.exe" init /home/andrew/jenkins/workspace/ReidacusOrg_siplogscanner_main #
timeout=10
GitHub has been notified of this commit’s build result
ERROR: Error cloning remote repo 'origin'**
Finished: FAILURE
Thanks in advance.
Solution
Do not use the approach of specifying 2 git configurations. Otherwise, you have to change every job. Just have one configuration and override the tool location at the agent/ node level. Only specify different tools where the variant matters. In your pipeline you'd reference :
tools {
jdk 'jdk1.8'
}
The Tools selector is intended to choose flavors of tools (jdk ver, openjdk vs oraclejdk, etc.). You override the tool location at the node level. My complete example was JDK, since versions matter, but also win/linux location differ. Git is just git.
Answered By - Ian W
Answer Checked By - Marie Seifert (JavaFixing Admin)