I am trying to define Jenkins pipelines as (shared) objects, as done here. But I want to add the capability to run build actions inside a docker container.
My Jenkinsfile
works like this:
@Library('ci-scons-jenkins') _
def image = docker.image("praqma/native-scons")
org.ipiq.buildci.scons.SConsPipeline.builder(this, steps, image).buildDefaultPipeline().execute()
As you can see, the docker instance is created in the Jenkinsfile and passed to the builder object to create the builder. So far, it works. Stages are executed inside
the container.
Now I want to transfer the creation of the Docker instance to the Pipeline class SconsPipeline.groovy
. I tried to do that with:
// I hoped it would import `Docker`
import org.jenkinsci.plugins.docker.workflow.*
class SConsPipeline implements Serializable {
def script
def stages
def image
DSL steps
static builder(script, DSL steps) {
// create the image to use in this build instead of using a parameter
def docker = Docker(script)
image = docker.image("praqma/native-scons")
return new Builder(script, steps, image)
}
But Jenkins fails to find the correct object:
groovy.lang.MissingMethodException: No signature of method: java.lang.Class.Docker() is applicable for argument types: (WorkflowScript) values:
So my question is how to use docker-workflow inside an object code in a shared library.