How to get a list of Jenkins Jobs using XML API

jenkins, perl, xml

Solution

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');

Problem

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) ```

Original source