Poor man’s xml parser for jenkins config

Angry jenkins is a nice tool but its users’ config is in XML. So what happens if on a production server one cannot install an XML parsing lib ?

Here is a little ditty to list users by role with the help of stingy global multiline regexp matching.

 

#!/usr/bin/perl
 $files=`ls /space/jenkins_instances/*/config.xml`;

print " JENKINS USERS by ROLE\n";

@files=split('\n',$files);

foreach my $file (@files) {
 my @parts=split('/',$file);
 my $client=$parts[3];
 print $client ."=> " . $file ."\n";
 print "-" x 78 . "\n";

my $contents="";
 open($FILE,"<",$file) || die "Cannot read file $1";
 while(<$FILE>) {
 $contents .= $_;
 }
 close($FILE);
 while ($contents =~ m/<role name="(.*?)" pattern="\.\*">(.*?)<\/role>/gsm ) {
 $role=$1;
 $perms_ids=$2;
 print $role .":";
$perms_ids=~ m/<assignedSIDs>(.*)<\/assignedSIDs>/sm;
$ids=$1;
while ($ids=~ m/<sid>(.*?)<\/sid>/gsm ) {
 print "\t". $1 ."\n";
 }
 print "\n";
}
 print "\n\n";
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: