I am currently facing challenges with importing the hudson.model.ParametersAction package in the Groovy console of Jenkins 2.452.4 sandboxed version. Despite attempts to import the package and set class paths for jenkins-core, setting system property hudson.model.ParametersAction.safeParameters=…, I have encountered restrictions that seem to prevent successful import.
Upon inspecting the jenkins-core jar file, it appears that the hudson and related model packages are null, potentially due to security measures in the sandboxed environment.
I am seeking guidance on how to securely set the value to a parameter so that I can effectively use the package within the restricted environment. Any insights, workarounds, or best practices for addressing import restrictions in a sandboxed Jenkins environment would be greatly appreciated.
Code is simple
import hudson.model.ParametersAction
error is
unable to resolve class hudson.model.ParametersAction
@ line 1, column 1.
Thank you in advance for your assistance and insights.
In a sandboxed Jenkins environment, certain classes and methods are restricted for security reasons.
The hudson.model.ParametersAction class is one of those restricted classes, which is certainly why you are encountering the error.
To work around this restriction, I think you could use the @NonCPS annotation to mark methods that should not be executed in the Groovy CPS (Continuation Passing Style) transformation. This allows you to bypass some of the sandbox restrictions. However, this approach should be used with caution as it can introduce security risks.
Here is an untested example of how you could maybe set a parameter value using the @NonCPS annotation:
Please note that using @NonCPS can bypass some of the sandbox restrictions, but it should be used with caution and only when necessary. Always review and test your scripts thoroughly to ensure they do not introduce security vulnerabilities.