I have a git project docker-build with the below class:
$ cat src/docker_build/DockerBuild.groovy
package docker_build
class DockerBuild {
def image
def steps
DockerBuild(steps) {
this.steps = steps
steps.docker.withRegistry('...', '...') {
image = steps.docker.image('...')
image.pull()
}
}
}
I tried to use the above class from a pipeline like this:
docker_build_lib = library(identifier: 'docker_build@master',
retriever: modernSCM( [$class: 'GitSCMSource', remote: '...', credentialsId: '...']))
docker_build = docker_build_lib.docker_build
pipeline {
agent "any"
stages {
stage("Init") {
steps {
script {
echo "GOT: ${d}"
}
}
}
}
}
The output I get is something like this:
$ docker login -u "..." -p ******** ...
Login Succeeded
[Pipeline] {
[Pipeline] echo
in withRegistry closure
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] echo
GOT: org.jenkinsci.plugins.docker.workflow.Docker$Image@7e65907b
My question is, why is DockerBuild.new() returning an object of type Docker$Image instead of docker_build.DockerBuild? Something weird is going on with the constructor and I am unable to even diagnose it. The output from any echo/println statements that I put in the constructor get lost except those that that get executed before the withRegistry() call. In fact, the output from image.pull() also gets lost. In another pipeline where I am doing a pull within the Jenkinsfile, I see output like this:
+ docker pull ...
Using default tag: latest
latest: Pulling from ...
Digest: sha256:f767e25c35c6977a336c080f16bd9c63fcdc04c405eb984d1c178e273d0547b8
Status: Image is up to date for ...
I am just following the
Loading libraries dynamically section and I do want to get this working with dynamically loaded libraries as I want to avoid the global static configuration that is associated with the @Library annotations. I would appreciate any help in diagnosing or getting this working.