Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48875

No closing tag while building xml file with MarkupBuilder in Pipeline Job

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • workflow-cps-plugin
    • Jenkins 2.89.2
      Pipeline: Groovy 2.41
      Pipeline 2.5

      Windows Server 2012 R2

      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>
      

       

            rkimble Arno Nym
            rkimble Arno Nym
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: