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

Static initialization block prevents mocking CpsThread

    Details

    • Similar Issues:

      Description

      This causes trouble for scripted pipelines testing, e.g. when using jenkins-spock library:

      Could not initialize class org.jenkinsci.plugins.workflow.cps.CpsThread
      java.lang.NoClassDefFoundError: Could not initialize class org.jenkinsci.plugins.workflow.cps.CpsThread
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.<init>(CpsScript.java:69)
      	at org.spockframework.mock.runtime.MockInstantiator.instantiate(MockInstantiator.java:33)
      	at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:155)
      	at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:68)
      	at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:59)
      	at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:40)
      	at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
      	at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:51)
      	at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:296)
      	at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:286)
      	at org.spockframework.lang.SpecInternals.SpyImpl(SpecInternals.java:161)
      	at com.homeaway.devtools.jenkins.testing.JenkinsPipelineSpecification.setup(JenkinsPipelineSpecification.groovy:1025)
      

        Attachments

          Activity

          Hide
          kamilszymanski Kamil Szymański added a comment -

          I've submitted a PR that fixes CpsThread mocking issue: https://github.com/jenkinsci/workflow-cps-plugin/pull/328

          Show
          kamilszymanski Kamil Szymański added a comment - I've submitted a PR that fixes CpsThread mocking issue:  https://github.com/jenkinsci/workflow-cps-plugin/pull/328
          Hide
          kamilszymanski Kamil Szymański added a comment -

          The reported problem was the result of having older version of groovy-cps on the classpath that got pulled in transitively hence the issue can be closed.
          Nevertheless I'd say that merging https://github.com/jenkinsci/workflow-cps-plugin/pull/328 or https://github.com/jenkinsci/workflow-cps-plugin/pull/336 would make this issue go away or be easier to debug for the ones to stumble upon it in the future.

          Show
          kamilszymanski Kamil Szymański added a comment - The reported problem was the result of having older version of groovy-cps on the classpath that got pulled in transitively hence the issue can be closed. Nevertheless I'd say that merging https://github.com/jenkinsci/workflow-cps-plugin/pull/328 or https://github.com/jenkinsci/workflow-cps-plugin/pull/336 would make this issue go away or be easier to debug for the ones to stumble upon it in the future.
          Hide
          kamilszymanski Kamil Szymański added a comment -

          This issue depends on the classpath and can be fixed by managing dependencies by the build tool.

          Show
          kamilszymanski Kamil Szymański added a comment - This issue depends on the classpath and can be fixed by managing dependencies by the build tool.

            People

            • Assignee:
              Unassigned
              Reporter:
              kamilszymanski Kamil Szymański
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: