1

The Jenkins file in my github repository is used in a Jenkins Master/Slave environment. I need to execute a testing command on a remote Jenkins Slave Server. In my declarative pipeline the agent is called like this:

stage("Testautomation") {
  agent { label 'test-device' }
    steps {
        bat '''
        @ECHO ON
        ECHO %WORKSPACE%
        ... '''
    }
}

Before Jenkins can even execute a remote command, it starts checking out from version control. The checkout on Jenkins Master is no problem and working fine. But on this Jenkins Slave I always receive this error message.

using credential github-enterprise:...
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://...git # timeout=10
Fetching upstream changes from https://...git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials GitHub Enterprise Access Token
 > git fetch --tags --force --progress --depth=1 -- https://...git +refs/heads/development:refs/remotes/origin/development # timeout=120
Checking out Revision ... (development)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f ...
Could not checkout ...
Florjud
  • 73
  • 2
  • 5

1 Answers1

5

The Declarative pipeline performs a SCM checkout on every agent by default. Check if Git is installed on the Jenkins slave.

Conversely, if you want the code to be checked out on master but not on the agent, disable the default checkout in the options directive and use the scm checkout step inside a stage.

pipeline {
    agent { label 'master' }
    options {
        skipDefaultCheckout(true)
    }
    stages {
        stage('Build') {
            steps {
                checkout scm
                // do other stuff on master
            }
        }
        stage("Testautomation") {
            agent { label 'test-device' }
            steps {
                bat '''
                    @ECHO ON
                    ECHO %WORKSPACE%
                '''
            }
        }
    }
}

You can further customize the checkout behavior as described in this answer https://stackoverflow.com/a/42293620/8895640.

Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25