I want to use Groovy in my Jenkins-Pipeline-Job to build a Statuslist of my Jenkins Slaves and the installed nodes. Therefore I have some lists which should be displayed in xml. While testing with IntelliJ i wrote the following code.

```
import groovy.xml.MarkupBuilder

def listNodeNames = []
listNodeNames << 'SLAVE1_NODE_1'
listNodeNames << 'SLAVE1_NODE_2'
listNodeNames << 'SLAVE2_NODE_1'
listNodeNames << 'SLAVE2_NODE_2'

def listComputerNames = []
listComputerNames << 'SLAVE1'
listComputerNames << 'SLAVE2'

def stringWriter = new StringWriter()
def xmlBuilder = new MarkupBuilder(stringWriter)

xmlBuilder.computers {
    for (i = 0; i < listComputerNames.size(); i++){

        xmlBuilder.computer {
            xmlBuilder.computerName("${listComputerNames[i]}")
            xmlBuilder.computerStatus("online")

            for (j = 0; j < listNodeNames.size(); j++){
                if (listNodeNames[j].contains(listComputerNames[i])){
                    xmlBuilder.slave {
                        xmlBuilder.slaveName("${listNodeNames[j]}")
                        xmlBuilder.slaveStatus('test')
                        xmlBuilder.slaveReason('test')
                    }
                }
            }
        }

    }
}

def xml = stringWriter.toString()
println xml

```

As long as i run the code in IntelliJ, everything works fine and i get a valid xml file:

```
  <computers>
      <computer>
        <computerName>SLAVE1</computerName>
        <computerStatus>online</computerStatus>
        <slave>
          <slaveName>SLAVE1_NODE1</slaveName>
          <slaveStatus>test</slaveStatus>
          <slaveReason>test</slaveReason>
        </slave>
        <slave>
          <slaveName>SLAVE1_NODE2</slaveName>
          <slaveStatus>test</slaveStatus>
          <slaveReason>test</slaveReason>
        </slave>
      </computer>
      <computer>
        <computerName>SLAVE2</computerName>
        <computerStatus>online</computerStatus>
        <slave>
          <slaveName>SLAVE2_NODE1</slaveName>
          <slaveStatus>test</slaveStatus>
          <slaveReason>test</slaveReason>
        </slave>
        <slave>
          <slaveName>SLAVE2_NODE2</slaveName>
          <slaveStatus>test</slaveStatus>
          <slaveReason>test</slaveReason>
        </slave>
      </computer>
    </computers>

```

But if i execute the same script on my Jenkins instance most closing tags are missing:

```
<computers>
  <computer>
    <computerName>SLAVE1</computerName>
    <computerStatus>online</computerStatus>
    <slave>
      <slaveName>SLAVE1_NODE1</slaveName>
      <slaveStatus>test</slaveStatus>
      <slaveReason>test</slaveReason>
      <slave>
        <slaveName>SLAVE1_NODE2</slaveName>
        <slaveStatus>test</slaveStatus>
        <slaveReason>test</slaveReason>
        <computer>
          <computerName>SLAVE2</computerName>
          <computerStatus>online</computerStatus>
          <slave>
            <slaveName>SLAVE2_NODE1</slaveName>
            <slaveStatus>test</slaveStatus>
            <slaveReason>test</slaveReason>
            <slave>
              <slaveName>SLAVE2_NODE2</slaveName>
              <slaveStatus>test</slaveStatus>
              <slaveReason>test</slaveReason>

```

Am i doing something wrong or are there specific steps to do while creating xml files via jenkins?