jenkinsci / phoenix-autotest-plugin

AutoTest Pipeline Plugin
http://surenpi.com
MIT License
2 stars 4 forks source link

Documentation for readXml #6

Closed ulrikls closed 5 years ago

ulrikls commented 5 years ago

I have an XML file like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServerList>
  <server>
    <machinename>clud-13783-r06</machinename>
    <status>COMPLETE</status>
  </server>
  <server>
    <machinename>clud-13783-t01</machinename>
    <status>INITIAL</status>
  </server>
</ServerList>

I want to get the status for a given machinename. Using

def xml = readXml xmlFile: 'servers.xml', nodeMap: [ status: "//server[machinename='${params.SERVER}']/status" ]
println xml.status

prints com.surenpi.jenkins.phoenix.model.XmlNodeResult@6f9f2970 How do I get the value of the status node? I've tried xml.status.text and xml.status.getText(), but both causes my pipeline to fail.

LinuxSuRen commented 5 years ago

Here's an example:

pipeline {
    agent any

    stages{
        stage("clone") {
            steps{
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/surenpi/xml']]])
            }
        }

        stage("xml") {
            steps{
                script{
                    def xml = readXml xmlFile: 'test.xml', nodeMap: [ status: "//server[machinename='clud-13783-t01']/status" ]
                    println xml.status.text
                }
            }
        }
    }
}
ulrikls commented 5 years ago

I thought that's what I did, but trying again today it works. Thank you for the quick reply.

LinuxSuRen commented 5 years ago

Please let me know if there are any questions.

ganesh-tavant commented 3 years ago

Is it mandatory to use nodeMap ?

kprasadbio commented 3 years ago

@LinuxSuRen

this is my xml structure:


<servlet>
    <servlet-name>productAppServlet</servlet-name>
    <servlet-class>compnay.apps.fnd.product.common.servlet.module</servlet-class>
    <init-param>
        <param-name>compnay.apps.fnd.product.productList</param-name>
        <param-value>product,hcm:orderdemo,product,scm:supply-chain,prc:procurement, ,payables,:expenses,joint-ventures,grc:grc,prj:grants-financials</param-value>
    </init-param>
</servlet>

<servlet-mapping>
<servlet-name>AppServlet</servlet-name>
      <url-pattern>/supply-chain/*</url-pattern>
      <url-pattern>/procurement/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/joint-ventures/*</url-pattern>
      <url-pattern>/product/*</url-pattern>
      <url-pattern>/grants-management/*</url-pattern>
      <url-pattern>/federal-financials/*</url-pattern>
</servlet-mapping>

on servlet/init-param/param-value, i need to append new string to existing one. on servlet-mapping, i need to add a new entry for url-pattern with a new value for it.

i been trying multiple ways like (xmllint, xpath, groovy) but nothing i could achieve, is it possible to do with current plugin?