Home > Software engineering >  How To Use groovy.xml.StreamingMarkupBuilder in Jenkins Pipeline
How To Use groovy.xml.StreamingMarkupBuilder in Jenkins Pipeline

Time:09-24

I am trying to modify an html file in a Jenkins pipeline and I need to add a span tag. In groovy I can do the following

def newNode = new StreamingMarkupBuilder().bind { span {mkp.yield("$child")}}

where child is a string to put in the span tag.

When I tried to do this in a Jenkins Pipeline, I got an error related to a CPS mismatch so I added @NonCPS but I am now getting an error that says java.lang.NoSuchMethodError: No such DSL method 'span' found among steps

I found this: https://www.jenkins.io/doc/book/pipeline/cps-method-mismatches/ that talks about CPS mismatches. I think it is basically trying to use the span tag as a DSL method, similar to stage or steps. So is it possible to somehow use the StreamingMarkupBuilder.bind() function like I am trying to without Jenkins interpreting the span tag as a DSL method?

CodePudding user response:

I ended up just creating a Node object separately. So I used the following line:

def node = new groovy.util.Node(null, 'span', child)

Then I just appended that node to another node using the append function.

  • Related