Docker – Jenkins docker pipeline error

dockergroovyJenkinsjenkins-pipeline

I'm trying to follow this tutorial to create a simple docker environment in as part of my jenkins pipeline build.

I'm trying to build a couple of docker images just as a test before I do my maven build. At the moment I have the following groovy for my Jenkinsfile:

#!groovy

node {

  stage 'Building docker env'
  def dbImage = docker.build('oracle', 'docker/oracle')
  def wlpImage = docker.build('liberty', 'docker/liberty')


  stage 'Running maven build'
  git url: 'https://mysite/myproject.git', branch: 'docker'
  def mvnHome = tool 'maven 3.3.9'
  sh "${mvnHome}/bin/mvn -B clean install"
}

I'm trying to have the docker build look in the directory "docker/oracle" and call the Dockerfile in that directory, and build the docker image named 'oracle', and same for liberty. At the moment though it's giving me this error:

Running on master in /root/.jenkins/workspace/pipeline_test
[Pipeline] {
[Pipeline] stage (Building docker env)
Using the ‘stage’ step without a block argument is deprecated
Entering stage Building docker env
Proceeding
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: docker for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)
    at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
...

Any ideas what could be the problem with the docker.build command I'm using? (or could it be something I forgot to install in Jenkins?)

Best Answer

The issue was I needed to install the Docker Pipeline plugin in Jenkins.