Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55479

Using workspace classes from multiple DSL scripts fails

    XMLWordPrintable

    Details

    • Similar Issues:
    • Released As:
      Job DSL 1.72

      Description

      Create a pipeline job with the following script:

      node('master') {
       writeFile file: 'a.groovy', text: 'new C()'
       writeFile file: 'b.groovy', text: 'new C()'
       writeFile file: 'C.groovy', text: 'class C {}'
       jobDsl targets: 'a.groovy,b.groovy', sandbox: true
      }
      

      Add appropriate authorization to the job and run it. It will fail with output like this:

      Started by user [...]
      Running as [...]
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] node
      Running on Jenkins in /var/jenkins_home/workspace/test
      [Pipeline] {
      [Pipeline] writeFile
      [Pipeline] writeFile
      [Pipeline] writeFile
      [Pipeline] jobDsl
      Processing DSL script a.groovy
      Processing DSL script b.groovy
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: Scripts not permitted to use new C
      Finished: FAILURE
      

      This only happens if multiple DSL scripts are used. If you change the jobDsl step to only run a.groovy, it works fine.

        Attachments

          Activity

          Hide
          daspilker Daniel Spilker added a comment -

          PR: https://github.com/jenkinsci/job-dsl-plugin/pull/1156

          I think the problem is that Job DSL re-uses the GroovyShell object, but the Script Security plugin creates a new sandbox for each script. Currently the Script Security does not provide an API to run multiple scripts in the same sandbox.

          To fix this I had to disable the GroovyShell cache. Running many scripts in sandbox mode will be slower.

          Show
          daspilker Daniel Spilker added a comment - PR: https://github.com/jenkinsci/job-dsl-plugin/pull/1156 I think the problem is that Job DSL re-uses the GroovyShell object, but the Script Security plugin creates a new sandbox for each script. Currently the Script Security does not provide an API to run multiple scripts in the same sandbox. To fix this I had to disable the GroovyShell cache. Running many scripts in sandbox mode will be slower.

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              rdonchen_intel Roman Donchenko
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: