[JIRA] [workflow-plugin] (JENKINS-32766) groovy.xml.MarkupBuilder fails in Pipeline with NoSuchMethodError

16 views
Skip to first unread message

jglick@cloudbees.com (JIRA)

unread,
Apr 28, 2016, 7:04:02 AM4/28/16
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
 
Jenkins / Bug JENKINS-32766
groovy.xml.MarkupBuilder fails in Pipeline with NoSuchMethodError
Change By: Jesse Glick
Summary: 'Official' Groovy XML authoring doesn't work groovy.xml.MarkupBuilder fails  in  pipeline:  Pipeline with  NoSuchMethodError
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.2#64017-sha1:e244265)
Atlassian logo

jglick@cloudbees.com (JIRA)

unread,
Aug 29, 2016, 4:24:02 PM8/29/16
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
Change By: Jesse Glick
Component/s: workflow-cps-plugin
Component/s: pipeline
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

thetypz@gmail.com (JIRA)

unread,
Jan 5, 2017, 4:32:02 AM1/5/17
to jenkinsc...@googlegroups.com
Francois Ferrand commented on Bug JENKINS-32766
 
Re: groovy.xml.MarkupBuilder fails in Pipeline with NoSuchMethodError

I managed to have this working: need to add 'delegate' before each tag:

xml.records() { 
    delegate.car(name:'HSV Maloo', make:'Holden', year:2006) {
        delegate.country('Australia')
        delegate.record(type:'speed', 'Production Pickup Truck with speed of 271kph')
    }
    delegate.car(name:'Royale', make:'Bugatti', year:1931) {
        delegate.country('France')
        delegate.record(type:'price', 'Most Valuable Car at $15 million')
    }
}

Maybe this is a problem with the closure delegation strategy, set to Closure.OWNER_ONLY ?

thetypz@gmail.com (JIRA)

unread,
Jan 5, 2017, 4:33:02 AM1/5/17
to jenkinsc...@googlegroups.com
Francois Ferrand edited a comment on Bug JENKINS-32766
I managed to have this working: need to add 'delegate' before each tag:


{code:java}

xml.records() {
    delegate.car(name:'HSV Maloo', make:'Holden', year:2006) {
        delegate.country('Australia')
        delegate.record(type:'speed', 'Production Pickup Truck with speed of 271kph')
    }
    delegate.car(name:'Royale', make:'Bugatti', year:1931) {
        delegate.country('France')
        delegate.record(type:'price', 'Most Valuable Car at $15 million')
    }
}
{code}

Maybe this is a problem with the closure delegation strategy, set to Closure.OWNER_ONLY
or a custom (e.g. Closure.TO_SELF) strategy which does not try the delegate ?

thetypz@gmail.com (JIRA)

unread,
Jan 5, 2017, 4:33:02 AM1/5/17
to jenkinsc...@googlegroups.com

thetypz@gmail.com (JIRA)

unread,
Jan 5, 2017, 4:42:01 AM1/5/17
to jenkinsc...@googlegroups.com
Francois Ferrand commented on Bug JENKINS-32766
 
Re: groovy.xml.MarkupBuilder fails in Pipeline with NoSuchMethodError

Delegation strategy is actually set correctly, but it seems that it is ignored when trying to resolve the function call: probably an issue in the sandbox interceptor or CpsScript/DSL invokeMethod.

neiltingley@java.net (JIRA)

unread,
Mar 2, 2018, 9:31:04 AM3/2/18
to jenkinsc...@googlegroups.com

Same problem and the above worked for me. 

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

jakub@pawlinski.pl (JIRA)

unread,
Jun 8, 2018, 8:42:02 AM6/8/18
to jenkinsc...@googlegroups.com

Same issue with html formatting, in script console ParseToHTMLTable method from below works fine:

 

import groovy.xml.MarkupBuilder
def ParseToHTMLTable(headers, params) {
  def writer = new StringWriter()
  new MarkupBuilder(writer).table() {
    tr {headers.each { title -> th(title) }}
    params.each { row ->
      tr {
        td(row.key)
        td(row.value)
      }
    }
  }
  return writer.toString()
}

def params = [
  "Job": "JobName",
  "isInQueue": true,
  "isBuilding": true,
  "isBuildBlocked": false,
  "Builds count": 15,
  "IsBuilding count": 1,
  "InProgress count": 1
]

println ParseToHTMLTable(["Parameter","Value"], params)

but in pipeline it requires multiple delegates:

 

 

import groovy.xml.MarkupBuilder
@NonCPS
def ParseToHTMLTable(headers, params) {
  def writer = new StringWriter()
  new MarkupBuilder(writer).table() {
    delegate.tr {headers.each { title -> delegate.delegate.th(title) }}
    params.each { row ->
      delegate.delegate.tr {
        delegate.td(row.key)
        delegate.td(row.value)
      }
    }
  }
  return writer.toString()
}

 

 

haridara@gmail.com (JIRA)

unread,
Oct 3, 2018, 1:46:03 PM10/3/18
to jenkinsc...@googlegroups.com

I want to try the delegator workaround, but getting this error: 
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.xml.MarkupBuilder java.io.Writer
It doesn't seem like this is whitelisted, so how is it working for others?

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

haridara@gmail.com (JIRA)

unread,
Oct 3, 2018, 1:47:02 PM10/3/18
to jenkinsc...@googlegroups.com
Hari Dara edited a comment on Bug JENKINS-32766
I want to try the delegator workaround, but getting this error: 
{noformat}
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.xml.MarkupBuilder java.io.Writer {noformat}
It doesn't seem like this is [whitelisted|https://github.com/haridsv/script-security-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist], so how is it working for others?

haridara@gmail.com (JIRA)

unread,
Oct 3, 2018, 1:48:02 PM10/3/18
to jenkinsc...@googlegroups.com
Hari Dara edited a comment on Bug JENKINS-32766
I want to try the delegator delegate workaround, but getting this error: 

{noformat}
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.xml.MarkupBuilder java.io.Writer {noformat}
It doesn't seem like this is [whitelisted|https://github.com/haridsv/script-security-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/generic-whitelist], so how is it working for others?

jakub@pawlinski.pl (JIRA)

unread,
Oct 5, 2018, 10:24:05 AM10/5/18
to jenkinsc...@googlegroups.com

Hari Dara you have to approve it yourself at http://yourhost:8080/scriptApproval/ or jenkins / manage jenkins / in-process script approval

haridara@gmail.com (JIRA)

unread,
Oct 5, 2018, 10:32:03 AM10/5/18
to jenkinsc...@googlegroups.com

Thanks Jakub Pawlinski, I am aware of that but was downplaying it as I don't really prefer that approach in a multi-tenant environment with no admin access. Won't it be safe to whitelist it?

vivek.pandey@gmail.com (JIRA)

unread,
Nov 15, 2018, 5:23:02 PM11/15/18
to jenkinsc...@googlegroups.com

agarthetiger@gmail.com (JIRA)

unread,
Nov 15, 2019, 4:49:03 AM11/15/19
to jenkinsc...@googlegroups.com
Andrew Garner commented on Bug JENKINS-32766
 
Re: groovy.xml.MarkupBuilder fails in Pipeline with NoSuchMethodError

This workaround using multiple delegates seems to be broken again. It was working for me using LTS v2.150.1 but with more recent releases and updates plugins it is not working again. I don't know whether it is the core Jenkins version or a plugin version that has reverted this issue.

I've changed my approach to use groovy.xml.DOMBuilder instead. The code is more verbose and it still requires many methods to be whitelisted, but I hope it is a more stable approach. See https://github.com/agarthetiger/jengu/blob/d9dddba3d1b7644216d088413638dbc84fba1ab4/vars/libraryTestRunner.groovy#L143

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages