Issue
I would like to use the CloudBees CD (CloudBees Flow) Perl API to look up the history for a procedure of a job.
Resolution
You can create a script that will query for all runs of a project (called test2
in the below script), for a specific procedure of that project (called testProcedure
in the below script):
use ElectricCommander; my $ec = ElectricCommander->new({ server => "localhost", }); # TODO update username and password $ec->login('username','password'); # TODO update "test2" and "testProcedure" my $result = $ec->findObjects({ objectType => 'job', filter => { operator => "and", filter => [{ propertyName => 'projectName', operator => "equals", operand1 => "test2" },{ propertyName => 'procedureName', operator => "equals", operand1 => "testProcedure" },], }, }); print $result->findnodes_as_string("/"). "\n";
This script is using the API command called findObjects
When you save the above script as a file, such as jobProcedureHistory.pl
and then run this perl script using the command:
ec-perl jobProcedureHistory.pl
You will see output similar to below, showing the history:
<responses version="2.3" dispatchId="2612" nodeId="10.0.2.15"> <response requestId="2" nodeId="10.0.2.15"> <objectId>job-e718c0c6-f5dc-11e9-8728-080027bd4d5b</objectId> <objectId>job-ee1f0064-f5dc-11e9-8728-080027bd4d5b</objectId> <objectId>job-f09e3193-f5dc-11e9-bb4c-080027bd4d5b</objectId> <object> <objectId>job-e718c0c6-f5dc-11e9-8728-080027bd4d5b</objectId> <job> <jobId>e718c0c6-f5dc-11e9-8728-080027bd4d5b</jobId> <jobName>job_28_20191023173433</jobName> <archived>0</archived> <combinedStatus> <message>Error</message> <status>completed_error</status> </combinedStatus> <createTime>2019-10-23T21:34:33.010Z</createTime> <directoryName>job_28_20191023173433</directoryName> <elapsedTime>1017</elapsedTime> <environmentWaitTime>0</environmentWaitTime> <external>0</external> <finish>2019-10-23T21:34:34.027Z</finish> <lastModifiedBy>admin</lastModifiedBy> <launchedByUser>admin</launchedByUser> <licenseReshareWaitTime>0</licenseReshareWaitTime> <licenseWaitTime>0</licenseWaitTime> <liveProcedure>testProcedure</liveProcedure> <modifyTime>2019-10-23T21:34:34.210Z</modifyTime> <outcome>error</outcome> <owner>admin</owner> <priority>normal</priority> <procedureName>testProcedure</procedureName> <projectName>test2</projectName> <propertySheetId>e718c0ca-f5dc-11e9-8728-080027bd4d5b</propertySheetId> <resourceWaitTime>0</resourceWaitTime> <start>2019-10-23T21:34:33.010Z</start> <status>completed</status> <totalWaitTime>0</totalWaitTime> <workspaceWaitTime>0</workspaceWaitTime> </job> </object> <object> <objectId>job-ee1f0064-f5dc-11e9-8728-080027bd4d5b</objectId> <job> <jobId>ee1f0064-f5dc-11e9-8728-080027bd4d5b</jobId> <jobName>job_29_20191023173444</jobName> <archived>0</archived> <combinedStatus> <message>Error</message> <status>completed_error</status> </combinedStatus> <createTime>2019-10-23T21:34:44.799Z</createTime> <directoryName>job_29_20191023173444</directoryName> <elapsedTime>1102</elapsedTime> <environmentWaitTime>0</environmentWaitTime> <external>0</external> <finish>2019-10-23T21:34:45.901Z</finish> <lastModifiedBy>admin</lastModifiedBy> <launchedByUser>admin</launchedByUser> <licenseReshareWaitTime>0</licenseReshareWaitTime> <licenseWaitTime>0</licenseWaitTime> <liveProcedure>testProcedure</liveProcedure> <modifyTime>2019-10-23T21:34:46.016Z</modifyTime> <outcome>error</outcome> <owner>admin</owner> <priority>normal</priority> <procedureName>testProcedure</procedureName> <projectName>test2</projectName> <propertySheetId>ee1f2778-f5dc-11e9-8728-080027bd4d5b</propertySheetId> <resourceWaitTime>0</resourceWaitTime> <start>2019-10-23T21:34:44.799Z</start> <status>completed</status> <totalWaitTime>0</totalWaitTime> <workspaceWaitTime>0</workspaceWaitTime> </job> </object> ...
Tested product version
CloudBees CD (CloudBees Flow) Version 9.1