1
votes

I've configured my Jenkins master to use docker and I can connect to docker, I've got a simple pipeline to test this:

node ('docker-build-slave') {
    stage ('On slave') {
        sh 'ls -l'
        sh 'uname -a'
    }
}

When I instigate a build and look at whats being written to the console, I get:

Started by user chris adkin
[Pipeline] node
Still waiting to schedule task
All nodes of label ‘docker-build-slave’ are offline

and it just hangs, I'm wondering if there is something really obvious I ave missed, do I need to create a node for my docker build slaves ?.

If I go onto the machine hosting jenkins, I can see that the build slave container have been started.

4

4 Answers

1
votes

The docker-build-slave that you supply is a label filtering the available Jenkins agents (master/slaves). If you do not have this label assigned either to the master or to any of the (available) slaves, this job cannot be built. Read more about labels

To let Jenkins pipeline, use the docker global variable, e.g. as described in this example:

node {
    checkout scm
    /*
     * In order to communicate with the MySQL server, this Pipeline explicitly
     * maps the port (`3306`) to a known port on the host machine.
     */
    docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw" -p 3306:3306') { c ->
        /* Run some tests which require MySQL */
        sh 'make check'
    }
}
0
votes

So after some digging around, and I am a bit shame faced to answer my own question, I came across this Jenkins article:

https://issues.jenkins-ci.org/browse/JENKINS-44859

I built my image using the Java JDK 7, the article states, and I quote from the comment added by Vinson Lee:

Jenkins 2.54+ requires Java 8.

I modified the docker file for my image to install open jdk 8 and everything is now working.

0
votes

The fix worked, this is the console output from successfully running the build job:

Started by user chris adkin
[Pipeline] node
Still waiting to schedule task
All nodes of label ‘docker-build-slave’ are offline
Running on docker-13b5a18eb067 in /home/jenkins/workspace/Pipeline With Docker Slave
[Pipeline] {
[Pipeline] stage
[Pipeline] { (On slave)
[Pipeline] sh
[Pipeline With Docker Slave] Running shell script
+ ls -l
total 0
[Pipeline] sh
[Pipeline With Docker Slave] Running shell script
+ uname -a
Linux localhost 4.9.49-moby #1 SMP Wed Sep 27 00:36:29 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
0
votes

If you use node {} with a specific label, and don't have any nodes with that label set-up, the build will be stuck forever, as mentioned by StephenKings answer. You also need to make sure you have at least 2 executors set-up when using a single node (like 'master'), otherwise pipeline builds will usually be stuck, as they consist of a root build and several sub-builds for the steps.