Job DSL 1.68 with import does not work as before (with Job DSL 1.59)

89 views
Skip to first unread message

Xavier Xemaire

unread,
Feb 26, 2018, 3:50:34 PM2/26/18
to job-dsl-plugin
Hello,

thank you very much for your great work. I'am very happy, that with the version 1.67 it is possible (again) to import utilities classes, like in Real-World-Examples
with activated scripting security.

But we have an error, that we didn't had with job DSL 1.59.
ERROR: (SubClass.groovy, line 8) No such property: crtMap for class: Utilities.SubClass

When I deactivate the option "Enable script security for Job DSL scripts", then it works. But I want that option.
When I define the attribute, then it works too.

Is there other restrictions with the script security options / groovy sandbox?

Details:

The SEED job runs the DSL in the groovy sandbox.
The authorize-project Plugin ist installed and "access control for builds" is set: project default build authorization has the strategy "Run as User who Triggered Build"
and I'm admin.

The files:
| ISP_DSL.groovy
|
\---Utilities
Basis.groovy
SubClass.groovy

We have 2 Classes: Basis (that defines 2 attributes process and prefix and some methods) and SubClass (that defines a default value for the attribute prefix).

The DSL ISP_DSL creates an object of type SubClass and defines a job:

Basis.groovy:

package Utilities

class Basis {
       
protected def process
       
protected def prefix
       
       
public String display() {
           
return  "Prefix ist: ${prefix} und process: ${process}"
       
}

       
void addFeature(def job) {
            job
.with {
                description
( this.display() )
           
}
       
}
}


SubClass.groovy:
You can see, that crtMap is a local variable to the constructor. I don't understand why I should define it as attribute of the class.
package Utilities

// crtMap is set with the default Map combined with the map.
class SubClass extends Basis {
       
// Constructor for SubClass, with Default value for prefix.
       
SubClass(Map map = [:]) {
               
super()
               
def crtMap = [prefix : "HUGO"] << map
               
this.prefix  = crtMap["prefix"]
               
this.process = crtMap["process"]
       
}
}


ISP_DSL.groovy
import Utilities.SubClass

def myJob = job("example")
def s = new SubClass(process: "BETRIEB")

s
.addFeature(myJob)


When I deactivate the option "Enable script security for Job DSL scripts", then it works. But I want that option.
When I define the attribute, then it works too:

SubClass.groovy (fixed)
package Utilities

// crtMap is set with the default Map combined with the map.
class SubClass extends Basis {
Map crtMap

SubClass(Map map = [:]) {
super()
crtMap = [prefix : "HUGO"] << map
this.prefix = crtMap["prefix"]
this.process = crtMap["process"]
}

}


Reply all
Reply to author
Forward
0 new messages