I'd like to use "$WORSKPACE" variable into a groovy file called by jenkins script. But all solutions found on SO failed :
// KO : Wks = build.getEnvironment(listener).get('WORKSPACE')
// KO : Wks = "${WORKSPACE}"
/* KO :
def thr = Thread.currentThread()
def build = thr?.executable
def envVarsMap = build.parent.builds[0].properties.get("WORKSPACE")
*/
// KO : def build = this.getProperty('binding').getVariable('build')
// KO : Wks = "%WORKSPACE%"
Message I got : Scripts not permitted to use method groovy.lang.GroovyObject setProperty java.lang.String java.lang.Object (JenkinsHelper.name). Administrators can decide whether to approve or reject this signature.
Any idea of code or option to set to allow Jenkins script to work ?
My sample case :
File JenkinsHelper.groovy :
class JenkinsHelper {
def init(String sln) {
Wks = "%WORKSPACE%"
}
}
return new JenkinsHelper();
Call from jenkins script :
def helper = load 'C:/.../test.groovy'
helper.init("Mon SLN")
Thanks :)