Executing external Groovy script in Jenkins 2

81 views
Skip to first unread message

Maciej Jaros

unread,
Aug 2, 2023, 5:55:56 AM8/2/23
to jenkins...@googlegroups.com
Hi.

I have some Groovy scripts that worked just fine in Jenkins 1.x but are now broken in 2.x. This is actually blocking my update, so I would be grateful for any suggestions on how to proceed.

I run the script in a post build step.


I already used Permissive Script Security to try and disable additional security added in Jenkins 2.x (which honestly I don't need as I'm the only person editing jobs).

It now breaks on this code I think:
```
// load class
def scriptDir = "/var/www/jenkins-groovy-helpers/JenkinsBuildHelper";
def parent = getClass().getClassLoader();
def loader = new GroovyClassLoader(parent);
def buildLogChecker = loader.parseClass(new File(scriptDir, "BuildLogChecker.groovy")).newInstance();
```

Jenkins 2.x says:
[PostBuildScript] - [INFO] Executing post build scripts.
ERROR: Build step failed with exception
groovy.lang.MissingMethodException: No signature of method: java.lang.Class.newInstance() is applicable for argument types: (java.util.LinkedHashMap) values: [[ignoreMode:false, ignoreLevels:[], maxLevel:error]]
Possible solutions: newInstance(), newInstance(), newInstance([Ljava.lang.Object;), isInstance(java.lang.Object)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:159)


Can I load a groovy class in some other way? Or maybe I can enable some standalone/single-user/single-admin mode or something that disables all this security checks?

As you can imagine `BuildLogChecker` is used to check log, but also needs access to job description as it sets descriptions based on errors in the job log (`build.setDescription(...)`). It also sets results:
```
if (!buildLogChecker.firstLogLines.error.isEmpty()) {
    build.setResult(Result.FAILURE);
} else if (!buildLogChecker.firstLogLines.warn.isEmpty()) {
    build.setResult(Result.UNSTABLE);
}
```

Regards,
Maciej Nux.

Maciej Jaros

unread,
Aug 2, 2023, 8:35:30 AM8/2/23
to jenkins...@googlegroups.com
'Maciej Jaros' via Jenkins Users (2023-08-02 11:55):

Can I load a groovy class in some other way? Or maybe I can enable some standalone/single-user/single-admin mode or something that disables all this security checks?


Reply all
Reply to author
Forward
0 new messages