linuxjenkinsbitbucketbeagleboneblackjenkins-agent

Don't want Jenkins Slave to clone repo?


My system is set up as a Docker Linux PC Master/BeagleBone Linux Slave, connected via USB SSH.

Essentially, I'm trying to do the following:

When I build from Jenkins, my master clones the repo, builds the code and stashes the binary. However, when I transfer to the 'flash' stage on the slave, it also tries to clone the repo (which fails due to credential problems - that's a separate issue). I don't want it to do this - rather, I want it to just take the newly stashed file and use that to flash the attached hardware, rather than look on the repo for it.

I seemingly can't find an option to prevent this from happening. What can I do to just use the stashed file? If it's not possible with stash, can it be done another way without the slave attempting to clone the repo?

Here's my Jenkinsfile:

pipeline { 
    agent none
    stages {
        stage('Build') {
            agent {
                label 'master'
            }
            steps {
                sh 'cd application/.../example && make'
                stash includes: 'application/.../example/example.bin', name: 'Flash'
            }
        }

        stage('Test of Flash') {
            agent {
                 label 'test_slave'
            }
            steps {
              unstash 'Flash'
              //Flashing step here
              sh 'make check || true'
            }
        }
    }
}

And here's the console log, starting with the master compiling:

obtained Jenkinsfile from 913...
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] node
Running on Jenkins in /var/jenkins_home/...
[Pipeline] {
[Pipeline] checkout
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository git@bitbucket.org:...

//Later, the file compiles:
Generating binary and Printing size information:...
//Compiles, then:
[Pipeline] stash
Stashed 1 file(s)
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test of Flash)
[Pipeline] node
Running on test_slave in /home/debian/...
[Pipeline] {
[Pipeline] checkout  //And it starts to clone the repo here!
Cloning the remote Git repository
Cloning with configured refspecs honoured and without tags
Cloning repository git@bitbucket.org:...

I don't want it to do the above.


Solution

  • Apparently, the same question was posted here in a different form: https://devops.stackexchange.com/questions/650/set-a-jenkins-job-to-not-to-clone-the-repo-in-scm/1074

    In any case, here's how to do it: you need to add an option called options { skipDefaultCheckout() } just after the first agent, so that in general, it does not poll the scm (since the command to check the git is checkout scm.)

    Then, in the stages you DO want to check the git, type checkout scm as a step.

    Here's the new Jenkinsfile:

    pipeline { 
        agent none
        options { skipDefaultCheckout() }  //THIS ONE
        stages {
            stage('Build') {
                agent {
                    label 'master'
                }
                steps {
                    checkout scm  //AND THIS ONE
                    sh 'cd application/...
                }
            }
            stage('Test of Flash') {
                agent {
                    label 'test_slave'
                }
                steps {
                  sh 'cd application/...
                  sh 'make check || true'
                }
            }
        }
    }
    

    (as it happened, stash was unnecessary.)