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

ClassCastException: DockerPipeline.image expects class String but received class CpsClosure2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • None
    • Jenkins ver. 2.89.2
      Pipeline: Declarative 1.2.6

      Up until very recently the Jenkinsfile example below with reusable docker agent definition worked great, however after rebuilding Jenkins using latest LTS docker image and reinstalling latest plugins from scratch I'm now getting ClassCastException as it seems to confuse docker 'label' and docker { options } formats.

      java.lang.ClassCastException: org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipeline.image expects class java.lang.String but received class org.jenkinsci.plugins.workflow.cps.CpsClosure2
      
      Caused: java.lang.IllegalArgumentException: Could not instantiate {image=org.jenkinsci.plugins.workflow.cps.CpsClosure2@614e9b7d} for DockerPipeline(image: String, alwaysPull?: boolean, args?: String, customWorkspace?: String, label?: String, registryCredentialsId?: String, registryUrl?: String, reuseNode?: boolean)
      
      def node = {
        label 'bar'
        registryUrl 'example.com'
        image 'node:1.2.3'
        args '--shm-size 1g'
      }
      
      pipeline {
        agent none
      
        stages {
          stage('0') {
            agent { label 'foo' }
            steps {}
          }
          stage('1') {
            agent { docker node }
            steps {}
          }
          stage('2') {
            agent { docker node }
            steps {}
          }
          stage('3') {
            agent { docker node }
            steps {}
          }
        }
      }
      

       

       

            abayer Andrew Bayer
            kozhevnikov Ilya Kozhevnikov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: