Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of Jenkins Jobs using XML API

Tags:

xml

jenkins

perl

I got the raw xml data from Jenkins REST API http://jenkins-host:8080/api/xml. Now I am working on getting the job name list out of this xml into a perl array or variable. following is the format of xml API

<hudson>
<job>
  <name>Test_Job1</name>
  <url>http://jenkins-host:8080/job/Test_job1/</url>
  <color>red</color>
</job>
<job>
  <name>Test_job2</name>
  <url>http://jenkins-host:8080/job/Test_job2/</url>
  <color>red</color>
</job>
<view>
  <name>Test_View</name>
  <url>http://jenkins-host:8080/</url>
</view>
</hudson>

Here I want to store Only the job names into an array not the view name. Ex:

@list = (Test_job1, Test_job2)
like image 349
MangeshBiradar Avatar asked Dec 27 '12 14:12

MangeshBiradar


1 Answers

With XML::Twig it would be:

#!/usr/bin/perl

use strict;
use warnings;

use XML::Twig;

my @jobs;
XML::Twig->new( twig_roots => { 'job/name' => sub { push @jobs, $_->text; } })
         ->parseurl( 'http://jenkins-host:8080/api/xml');
like image 183
mirod Avatar answered Nov 05 '22 22:11

mirod