0

I have the following in a Jenkins file where I am trying to get some text from an XML file:

    pipeline {
      agent any
      stages {
        stage('Start') {
          steps {
            echo 'Build start'  
            script {
              def xml = readFile "${env.WORKSPACE}/config.xml"
              def xmlContents = new XmlParser().parseText(xml)
              def text = xmlContents.text()
              echo 'contents are...'
              echo text
              
            }
          }
        }
    .....

This causes the following exception

    org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.util.XmlParser parseText java.lang.String
        at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:262)
        at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:161)
        at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:156)
        at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:160)
        at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
        at WorkflowScript.run(WorkflowScript:9)

According to a solution to this problem as posted here, I need to go in and set the In-process Script Approval, however I have done this a couple of times..

enter image description here

Also, elsewhere, I have seen comments to disable sandbox mode, but I do not have this option as shown in other screen shots...

enter image description here

Perhaps things have changed.

So, my question is, how can I read the contents of an XML file if can't use the XMLParser? Or how can I use the XMLParser?

halfer
  • 19,824
  • 17
  • 99
  • 186
peterc
  • 6,921
  • 9
  • 65
  • 131
  • I now know you need to approve each individual method call, so once I just kept approving, it began to work – peterc Jun 12 '19 at 23:06
  • In that case it is best to post yourself the solution as answer and accept it, so it shows in the list as resolved and others who find your question with the same problem can find the answer quickly =) – Dominik Gebhart Jun 14 '19 at 09:42

1 Answers1

0

I have since found that you just need to keep approving each individual method (including constructors), one at a time. Ie, you may approve one, and then you get the next error.

I did not notice that they were subtley different approvals required.

peterc
  • 6,921
  • 9
  • 65
  • 131