1
我有下詹金斯API腳本:例如GET值包含XML
import jenkins
import json
import re
server = jenkins.Jenkins('https://jenkins_url', username, password)
nodes = json.dumps(server.get_nodes())
nodes = re.sub('\"offline\"|[:{} \[\]]|true,|false,|\"name\"|\"','',nodes).split(',')
for label in nodes:
if label != 'master':
print label
node_config = server.get_node_config(label)
print node_config
node_config包含下一XML文本:
<?xml version="1.0" encoding="UTF-8"?>
<slave>
<name>test.server</name>
<description></description>
<remoteFS>/var/lib/jenkins</remoteFS>
<numExecutors>1</numExecutors>
<mode>EXCLUSIVE</mode>
<retentionStrategy class="hudson.slaves.RetentionStrategy$Always"/>
<launcher class="hudson.plugins.sshslaves.SSHLauncher" plugin="[email protected]">
<host>test.server</host>
<port>7777</port>
<credentialsId>d0970a8f-d124</credentialsId>
<maxNumRetries>0</maxNumRetries>
<retryWaitTime>0</retryWaitTime>
</launcher>
<label>BuildServer</label>
<nodeProperties/>
<userId>test</userId>
</slave>
我想每個標籤的價值以獲得輸出,例如test.server等
你能幫我嗎?
我工作,但它不打印我想要什麼。 – user54
它打印所有除: test.server d0970a8f-D124 credentialsId> 0 maxNumRetries> 0 retryWaitTime> –
user54
我已經找到錯誤:而不是root.findall('name')我必須把root.findall('.// host')。根據文檔「//」選擇當前元素下的所有級別上的所有子元素(搜索整個子樹)。例如,「。// egg」選擇整個樹中的所有「蛋」元素等。感謝您的幫助! – user54