Jenkins xml rest API获取作业名称列表和按名称过滤的最后一个构建号

时间:2018-03-22 06:27:16

标签: jenkins jenkins-api

我想获取所有作业名称的列表以及按作业名称过滤的最后一个版本号。我试着使用以下内容 -

https://blahblahxxxxx/jenkins/api/xml?tree=jobs[displayName,lastBuild[number]]&xpath=/hudson/job&includes=/hudson/job/displayName[contains(.,%27myjobnamefilter%27)]&wrapper=job_names&pretty=true

但是这只会提供所有作业及其最后的构建号,而不会过滤作业名称。

e.g。

<job_names>
  <job>
    <displayName>blahjob</displayName>
    <lastBuild>
         <number>25</number>
    </lastBuild>
  </job>
  <job>
    <displayName>blahblahblahjob</displayName>
    <lastBuild>
         <number>49</number>
    </lastBuild>
  </job>
<job_names>

1 个答案:

答案 0 :(得分:1)

你做得对。但是您需要定义多个值,而不是使用[contains(.,%27myjobnamefilter%27)]。而是使用[. = 'name1' or . = 'name2']。此处name1name2是您获得的职位名称。有关详细信息,请阅读this thread

https://blahblahxxxxx/jenkins/api/xml?tree=jobs[displayName,lastBuild[number]]&xpath=hudson/job[displayName[. = 'name1' or . = 'name2']]&wrapper=job_names&pretty=true

希望这有帮助。

相关问题