Groovy DSL is not working

Issue

After moving from Jenkins OSS to CloudBees CI, we have observed that we cannot generate our DSL pipelines without errors.

We see errors like the ones shown below:

Processing DSL script DSL/my_script.groovy
ERROR: startup failed:
my_script.groovy: 1: unable to resolve class My_Class
@ line 1, column 1.
import My_Class

Environment

Resolution

In order to be able to run Groovy DSL scripts in Cloudbees CI you will need to follow different steps due to the security hardening existing in the platform compared to Jenkins OSS.

  • First of all you need to install the Authorize project plugin.
  • After restarting the instance, you will need to enable it. You can do it by browsing to Manage Jenkins->Configure Global Security->Access Control for builds section as shown below:

  • Enable it and set the Run as specific user checkbox.

  • Once done, you will need to go to the Job configuration page and click on the lock that will show up in the left menu. Once there, configure the userid that works for you (we used admin, but can be any user with the right permissions).

  • Finally, configure the job and enable the Groovy Sandbox.

Upon finishing all these steps, when you try to run the job you will be prompted to approve some scripts and methods, but once that you have done that, you will be able to run the job without further problems.

Tested product/plugin versions

Have more questions?

0 Comments

Please sign in to leave a comment.