login Signup

ecperl- How do I get the information inside a job link or job details page ?

This is what I do - search for jobs that contain "trunk-coolApp-" in Electric commander web UI. These are just builds for the application coolApp which look like this trunk-coolApp-{build number goes here}. Pick one job/build and click its link which leads me to the "job details page". In the job details page, there is an "svn info link". There are also tabs for - steps, diagnostics, parameters, properties etc. The svn info link leads to a page which only contains text.

Now, I just learned how to use perl instead of the web UI to search for the above jobs. I want to use the EC perl api to also get the text inside the "svn info link" of a job. Is this even possible ? If yes, are there any ec-perl functions that do this ? My goal is to get the svn info for a couple of builds, parse them and find the last check in.

Currently, I don't get the last checkin because of the way EC is setup. When EC finds a new check in for coolApp, it will generate a build and put the revision info (last check in, who made the change etc.) inside the svn info for that build. After that, if there is no check in, it will insert nothing in the svn info. I am frustrated by this. I need to manually scan each build to see the last check in for that build.

Please help me to do this. Thanks.

avatar image By electricfool 22 asked Oct 26, 2014 at 01:13 PM
more ▼
(comments are locked)
avatar image electricfool Oct 26, 2014 at 01:17 PM

PS - Is this the right way to solve the problem ?

10|750 characters needed characters left

3 answers: sort voted first

Since this is too long to fit in a comment to my previous answer, here it is as a separate answer.

To expand on the code that johntconklin wrote for you in an earlier question, this is a fuller program. The better way for you to do it would be to follow tanay's advice above, but if you don't know and don't know how to get the information he asked about, you can do it this way.

 use strict;
 use warnings;
 use ElectricCommander;
 my $ec = ElectricCommander->new();
 $xpath = $ec->login("username", "password");
 print $xpath->findnodes_as_string('/') . "\\n";
 my $xpath = $ec->findObjects('job',
     maxIds => 10,
     filter => [
                   operator => 'and',
                   filter => [
                     {"propertyName" => "jobName",
                      "operator" => "contains",
                      "operand1" => "trunk-utils"},
                     {"propertyName" => "svnCode",
                      "operator" => "equals",
                      "operand1" => "123456"},
 ###print $xpath->findnodes_as_string('/') . "\\n";
 my @jobsEC = $xpath->findnodes("//object/job");
 foreach my $job (@jobsEC)
     my $jobName = $job->findvalue("jobName")->value;
     my $jobId = $job->findvalue("jobId")->value;
     my $projectName = $job->findvalue("projectName")->value;
     my $start = $job->findvalue("start")->value;
     my $outcome = $job->findvalue("outcome")->value;
     my $procedureName = $job->findvalue("procedureName")->value;
     my $scheduleName = $job->findvalue("scheduleName")->value;
     my $launchedBy = $job->findvalue("launchedByUser")->value;
     print "$jobName\t$outcome\t$projectName:$procedureName\t$scheduleName\t$launchedBy\t$start\n";
     my $reportUrl = $ec->getProperty("report-urls/svn info link",
         {jobId => $jobId})->findvalue("//value")->value;
     print "     $reportUrl\n\n";
 $xpath = $ec->logout();
 print $xpath->findnodes_as_string('/') . "\\n";

This prints out the URL for the "svn info link". You then have to use some way, such as "wget", to retrieve the information from that link.

The program also prints the information in more like the table you requested earlier.

To parse the information returned to you by ElectricCommander, it would be a good idea to read the documentation on the XPath module, which is available from CPAN and is included with ElectricCommander.

avatar image By sbarry 1.5k answered Oct 31, 2014 at 01:53 PM
more ▼
(comments are locked)
avatar image sbarry Oct 31, 2014 at 01:55 PM

"ask" seems to have doubled all my backslashes. You'll need to remove the extra ones to use the code.

avatar image electricfool Nov 04, 2014 at 01:34 PM

@sbarry - I got an error. I am new to perl, so I have no idea of how to fix it. I googled and found some solutions here - http://perlmaven.com/global-symbol-requires-explicit-package-name But those also did not work. Not sure if I should turn strict off. Please help me. Thanks. ----> Global symbol "$xpath" requires explicit package name at c:\code\BlackPearl.pl line 7. Global symbol "$xpath" requires explicit package name at c:\code\BlackPearl.pl line 8. Execution of c:\code\BlackPearl.pl aborted due to compilation errors.

avatar image sbarry Nov 04, 2014 at 01:44 PM

Sorry. I commented out some of the lines when I was testing.

Move the "my" in front of the findObjects() line to in front of the login() line.

Also, rememember to use ec-perl when compiling it.

avatar image electricfool Nov 04, 2014 at 05:56 PM

@sbarry - Your code lets me get the "svn info link" for a job. But, it does not give me the text inside that link. Is it possible to also include that text inside the xml output ? Thanks.

avatar image electricfool Nov 04, 2014 at 06:33 PM +

@sbarry - thanks once again. The code throws and exception when there is no "svn info link" for a job. This can happen when the job is running, aborted or errors out too soon. Can you please modify the code to handle this exception ? If possible, can you please make it say ERROR:SVN_LINK_NOT_MADE. As an aside, if you also add some code to get the contents of the urls, then the code should not go to url if url = this error message. I would have learned perl, but this is just a one time job for me. I don't need perl anymore after this. So, I am dependent on your expert help for this. Thanks.

10|750 characters needed characters left

If you were using Linux, you might be able to use the "wget" command.

You can check to see if there is something similar for Windows.

avatar image By sbarry 1.5k answered Oct 30, 2014 at 06:09 PM
more ▼
(comments are locked)
10|750 characters needed characters left

For each job, you can find the SVN revision number stored in a property like this on the job: /jobs/JOB_ID/ecscm_snapshots/Subversion-http:::SVN_SERVER:PATH:TO:REPOSITORY (e.g. with a job ID of 1234 and an SVN URL of, the property would be /jobs/1234/ecscm_snapshots/Subversion-http::: I would get to that property and then called "svn info" on the revision.

Note: I tested this out with ECSCM- and ECSCM-SVN- installed on my EC 5.2 system.

avatar image By tanay ♦ 3.4k answered Oct 27, 2014 at 01:24 AM
more ▼
(comments are locked)
avatar image electricfool Oct 29, 2014 at 03:43 PM

I clicked the link for "svn info" for one job for the app. The partial url looks like this - jobs/aaa-bbb-ccc-111/shared%20build/temp.log.txt . How do I get the svn text from this, using the ec-perl code. Please help me. Thanks.

avatar image mike westerhof Nov 04, 2014 at 08:45 PM

We are forced to make "guesses" about the nature of the jobs that you are querying -- you need to understand that there are no "standard" jobs provided with Commander; rather each job is coded by the team using it, and they, when they write the procedure, choose what data to expose.

Based on your most recent comment above, the job's author chose to place the SVN info into the filesystem rather than in Commander -- you cannot reliably fetch the content of that log file from your code; there is no API to do so. Instead, change the job so that the desired data is stored as a property.

avatar image electricfool Nov 05, 2014 at 01:46 AM

@Mike Westerhof - Yes, that makes sense. I was hoping to get that info with the perl code itself. Now I will have to beg the developers to change the job as per my needs. I am not sure how much effort this will take and if it will break existing scripts. I'll try that and get back. Thanks for all your patience and support ! It means a lot to me.

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.