Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-43190

Cannot access to docker step in second level closure

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • docker-workflow-plugin
    • Jenkins 2.51
      Docker plugin 0.16.2
      Docker pipeline 1.10
      Docker Commons plugin 1.6

      I'm using jenkins pipeline with global variables.

      The definition of my job is :

      DBTest{
          prepareDB = {
              dbImgName="ibmcom/db2express-c:latest"
              this.docker.image(dbImgName).pull()
              dbContainerId = sh returnStdout:true, script:"docker run -d ${dbImgName} /init_db.sh"
              return dbContainerId 
          }
      }

      and DBtest.groovy is like :

      def call(body) {
      	// evaluate the body block, and collect configuration into the object
      	def config = [:]
      	body.resolveStrategy = Closure.DELEGATE_FIRST
      	body.delegate = config	
      	body()
      	
      	properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '14', numToKeepStr: '14')), pipelineTriggers([cron('H H * * *')])])
      	node("docker"){
      		wrap([$class: 'TimestamperBuildWrapper']) {
      			dbDockerId=null
      			testImg=null
      			testImgName=(config.testImgName == null || config.testImgName.isAllWhitespace())?"internal/jalios-ant-builder:dev":config.testImgName	
      			options=["JCMS=JCMS"]
      			
      			try{
      				stage("prepare DB"){
      					dbDockerId = prepareDB(config, body)
      				}
      			 }
      			catch(Exception e){
      			  failBuild("Cannot execute DB test ",e, currentBuild)
      			}
      		}
      	}
      }
      
      def prepareDB(config, body){	
      	if(config.prepareDB){
      		config.prepareDB.delegate = body.owner
      		return config.prepareDB.call(steps)
      	}
      	else{
      		throw new IllegalStateException("no prepareDB closure are available !!")
      	}
      }
      

       

      My problem is that I cannot understand why I cannot call directly docker step in my prepareDB closure, like echo or sh step.

      After some tests, I find that this.docker step is working.

      Note : if docker step is called inside the DBTest.groovy, it's working correctly.

            Unassigned Unassigned
            lsmadja ludovic SMADJA
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: