Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-54334

Declarative pipeline tools directive does not support git

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None

      On our jenkins master runs on a linux host and we've configured two git tools to be used on our slaves on the

      http://<hostname>/jenkins/webapp/configureTools/

      page

      1. Default - Linux git binary
        1. /usr/bin/git
      2. gitwin - Windows git binary
        1. C:\Program Files\Git\bin\git

      Every Linux/Windows slaves in our infrastructure has git installed in the above location. On each slave configuration page, we don't override the 'Tools locations' and instead depend on inheriting the tools configured on the master.

      For a Pipeline job with the Jenkinsfile stored in the jobs' config.xml - a job scheduled on a windows node correctly picked up the configured git tool

      pipeline {
          agent {  label '(build) && win2k8' }
          tools { git "gitwin" }
          stages {
              stage('Compile') {
                     stage('Windows') {
                          steps {
                              echo "Compiling code...."
                              sleep 10
                          }
                     }
              }
          }
      }
      

       

      For a Pipeline job with the Jenkinsfile (same Jenkinsfile as listed above) stored in SCM - a job scheduled on a windows node does not correctly pick up the git tool configured. Instead it defaults to the first configured tool, which happens to be a linux path and hence fails on windows. The following blog post documents this issue and suggests using the checkout pipeline step to override the gitTool. I tried this and it didn't work either.

      pipeline {
          agent {  label '(build) && win2k8' }
          tools { git "gitwin" }
          stages {
              stage('Compile') {
                     stage('Windows') {
                          steps {
                                  checkout([
      							$class: 'GitSCM', branches: [[name: '*/master']], gitTool: 'gitwin',
      							userRemoteConfigs: [[ credentialsId: null, url: 'http://<internally-hosted-git-url>.git' ]]
      							])
                              echo "Compiling code...."
                              sleep 10
                          }
                     }
              }
          }
      }
      

      Job log with error that highlights the slave trying to use the Default git tool rather than the overridden 'gitwin' tool configured in the Jenkinsfile

      [Pipeline] node
      Running on VMWASXXXXX in C:\workspace\msde-jenkinsfile-sample-windows
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Declarative: Checkout SCM)
      [Pipeline] checkout
      Cloning the remote Git repository
      Cloning repository http://<internally-hosted-git-url>.git
       > /usr/bin/git init C:\workspace\msde-jenkinsfile-sample-windows # timeout=10
      ERROR: Error cloning remote repo 'origin'
      hudson.plugins.git.GitException: Could not init C:\workspace\msde-jenkinsfile-sample-windows
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:787)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:579)
      	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
      	at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:212)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
      	at hudson.remoting.Request$2.run(Request.java:369)
      	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
      	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 hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93)
      	at java.lang.Thread.run(Thread.java:748)
      	Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from <internal-IP-address>/<internal-IP-address>:<internal-port>
      		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
      		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
      		at hudson.remoting.Channel.call(Channel.java:955)
      		at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:146)
      		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      		at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      		at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      		at java.lang.reflect.Method.invoke(Method.java:498)
      		at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:132)
      		at com.sun.proxy.$Proxy99.execute(Unknown Source)
      		at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1146)
      		at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
      		at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:120)
      		at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:90)
      		at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:77)
      		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:50)
      		at hudson.security.ACL.impersonate(ACL.java:290)
      		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:47)
      		at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      		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)
      		... 1 more
      Caused by: hudson.plugins.git.GitException: Error performing command: /usr/bin/git init C:\workspace\msde-jenkinsfile-sample-windows
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2023)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1984)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1980)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1612)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:785)
      	... 12 more
      Caused by: java.io.IOException: Cannot run program "/usr/bin/git" (in directory "C:\workspace\msde-jenkinsfile-sample-windows"): CreateProcess error=2, The system cannot find the file specified
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
      	at hudson.Proc$LocalProc.<init>(Proc.java:249)
      	at hudson.Proc$LocalProc.<init>(Proc.java:218)
      	at hudson.Launcher$LocalLauncher.launch(Launcher.java:935)
      	at hudson.Launcher$ProcStarter.start(Launcher.java:454)
      	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2012)
      	... 16 more
      Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
      	at java.lang.ProcessImpl.create(Native Method)
      	at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
      	at java.lang.ProcessImpl.start(ProcessImpl.java:137)
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
      	... 21 more
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: Error cloning remote repo 'origin'
      Finished: FAILURE
      

            Unassigned Unassigned
            croydondias Croydon Dias
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: