Jenkins error "No such property: docker for class: groovy.lang.Binding"

37.3k Views Asked by At

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 images named oracle, and 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?)

5

There are 5 best solutions below

0
On BEST ANSWER

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


To install the plugin using the GUI:

Dashboard > Manage Jenkins > Manage Plugins > Available (tab) > docker-workflow.

1
On

Maybe I'm missing some part of your code, but where do you define the docker? If that's the complete Groovy script, you're trying to bind a variable which isn't declared anything, so it's not to weird that it fails, right?

Just define a docker it that's what you want, like:

def docker = "my docker" // something similar like this

And it will at-least resolve your missing property exception.

Whenever we see the error like below :

groovy.lang.MissingPropertyException: No such property: 

It means , groovey script did not able to find the property mentioned post the colon sign : , so we need to either define the user defined variable/property or use the correct one from API.

0
On

I had the same issue but after I installed the Docker Pipeline plugin as @Affes Salem suggested it is working now.

0
On

If you have this issue:

groovy.lang.MissingPropertyException: No such property: docker for class: groovy.lang.Binding.

We most likely encountered the same issue, in order to fix it I only had to install the Docker Pipeline plugin in Jenkins, so all you have to do is go to:

Jenkins Homepage > Manage Jenkins > Manage Plugins > Available

Search for Docker Pipeline install it restart jenkins and you are ready to go.

For more info about Docker Pipeline Plugin Scripts click here.

1
On

As Pete says you will have to install the Docker Pipeline plugin. You can do that though the Jenkins UI.