Trouble using MarkupBuilder DSL within Pipeline DSL

549 views
Skip to first unread message

David Karr

unread,
Nov 15, 2016, 12:24:48 PM11/15/16
to Jenkins Users
In my Jenkinsfile, I'm trying to use MarkupBuilder to construct a simple XML message. I first discovered that there are default security restrictions preventing the use of this class, which I was able to override.

Next, I'm seeing errors that make it seem like the "methodMissing" calls for XML elements within the MarkupBuilder DSL are going to the Pipeline DSL instead.  I'm able to verify my method works in groovyConsole, but when I run the job in Jenkins, I get an error like this:
java.lang.NoSuchMethodError: No such DSL method 'statement' found among steps [VersionNumber, archive, ...

Where my method looks like this:
def constructMessageXML(String qid, String qpassword, String contactID, String text, boolean isMeeting) {
   
def writer = new StringWriter()
   
MarkupBuilder mb    = new MarkupBuilder(writer)
    mb
.message (type:"contact.send.message", id:qid, password:qpassword, contactId:contactID) {
        statement
(isMeeting ? [from:qid, to:contactID, text:text, type:"meeting"] : [from:qid, to:contactID, text:text]) {}
   
}
   
return writer.toString()
}


The list of steps from the error message are clearly from the Pipeline DSL, not the MarkupBuilder DSL.

David Karr

unread,
Nov 15, 2016, 12:38:22 PM11/15/16
to Jenkins Users

Someone I work with suggested I add @NonCPS to the method.  That didn't make any difference.

David Karr

unread,
Nov 15, 2016, 3:23:43 PM11/15/16
to Jenkins Users
On Tuesday, November 15, 2016 at 9:24:48 AM UTC-8, David Karr wrote:

I've managed to resolve this.  Changing "statement" to "delegate.statement" gets past this.

André Lanouette

unread,
Mar 21, 2017, 5:01:14 PM3/21/17
to Jenkins Users
Hello,

Sorry to hijack this thread, but I am attempting to use the MarkupBuilder to generate POM aggregators project on the fly from my Jenkins Pipeline. However, I am also having a security issue when instantiating the MarkupBuilder:

 Scripts not permitted to use new groovy.xml.MarkupBuilder java.io.Writer

You say you have been able to override this. Would you be willing to share with me how to achieve this?

Thank you

Cuong Tran

unread,
Mar 21, 2017, 10:49:33 PM3/21/17
to Jenkins Users
You need to approve it in the "In-process Script Approval" page under /manage.


On Tuesday, November 15, 2016 at 9:24:48 AM UTC-8, David Karr wrote:

niristotle okram

unread,
Apr 6, 2017, 10:40:19 PM4/6/17
to jenkins...@googlegroups.com
Seems like there is more shit apart from the security!!! The if you are using the java file writer, in a distributed env it doesn't work. 
I can generate some nice xml's on the master but not in the slave. What a shame!

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/63d4680d-4ae5-4920-9a5c-5facb4486eee%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards
nirish okram
Reply all
Reply to author
Forward
0 new messages