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

Cannot create a new instance of a pipeline shared library class

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • script-security-plugin
    • None
    • Master: Atomic CentOS
      Slave: Windows Server 2012 R2 x64

      I have a class in a pipeline shared library (which is stored in a deployed Github repository):

      package com.xxx
      
      class ArtifactoryPublisher implements Serializable {
      
      def script
      def host
      
      ArtifactoryPublisher(script, host) { 
      this.script = script
      this.host = host
      }
      
      def push(feed, pattern = "*.nupkg") {
      
      def artifactory = Artifactory.server this.host
      
      def uploadSpec = """{
      "files": [
      {
      "pattern": "$pattern",
      "target": "$feed"
      }
      ]
      }"""
      
      def buildInfo = artifactory.upload(uploadSpec)
      artifactory.publishBuildInfo(buildInfo)
      }
      
      }
      

      When I try to instantiate this in a Jenkinsfile:

      def apub = new ArtifactoryPublisher('art01')
      

      I get this:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified new com.xxx.ArtifactoryPublisher java.lang.String
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:126)
      	at org.kohsuke.groovy.sandbox.impl.Checker$3.call(Checker.java:191)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedConstructor(Checker.java:188)
      	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.constructorCall(SandboxInvoker.java:20)
      	at WorkflowScript.run(WorkflowScript:78)

      However, it does not show up as a pending script approval.

       

      PS it is possible to create other objects from shared libraries, e.g.

      def slack = new Slack(this, mySlack.team, mySlack.channel)
      

          [JENKINS-43041] Cannot create a new instance of a pipeline shared library class

          Jesse Glick added a comment -

          Mismatch in constructor argument count.

          Jesse Glick added a comment - Mismatch in constructor argument count.

            Unassigned Unassigned
            stephendrew Stephen Drew
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: