x
login Signup

Create url to launch a job

Is there a way to create a url that is pinned to a job that when clicked with either automatically start a job, or navigate to the job run page with options from the url placed in parameter fields?

Edit: For clarification, the reason that I would like this link is that a job that is run creates an artifact that you "could" do something with. I want to have a link on the job page so that if they want to use it, they can just click the button and it will launch a different job using this created artifact.

avatar image By mike wright 25 asked Oct 22, 2012 at 08:17 PM
more ▼
(comments are locked)
10|750 characters needed characters left

3 answers: sort voted first

There is a way to programatically construct a URL that will run a procedure. Here's an example that is hopefully enough for you to copy the pattern:

  ectool setProperty "/myJob/report-urls/Run Another Procedure" "/commander/runProcedure.php?runNow=1&projectName=$[/myProject/projectName]&procedureName=SimpleProcWithParams&numParameters=1&parameters1_name=foo&parameters1_value=$[/myJob/jobId]&parameters2_name=bar&parameters2_value=1111"

When run from a Commander jobStep, this creates a link on the Job Details page of the job that will run another procedure. In this case, I'm using a property reference to insert the name of the current Project, so the the procedure to run would have to exist in the same Project.

A common use-case for doing something like this is that you want to run another job (i.e. start a procedure) that will operate on some metadata contained in the current job. In this case, you will often pass the current job's jobId as one of the parameters so that the secondary job can refer to this job's properties.

Note that any text that you insert into this URL via a property reference should be uri-encoded in order to create a proper URL. In Perl, this can be done with the URI::Escape module. Here's an example of Perl code that might run in a step that shows how to do this:

   use strict;
   use ElectricCommander;
   use URI::Escape;
   $| = 1;
   my $gECommander = ElectricCommander->new();
   
   
   # Create a link to "restart" the job
       CreateLink("Restart from Failure Point", 
                   {
                       configuration       =>  '$[configuration]',
                       restartFromBuild    =>  '$[jobName]',
                   });
   
   
   #-------------------------------------------------------------------------
   #   CreateLink 
   #
   #       Add a link to re-run the job
   #
   #-------------------------------------------------------------------------
   sub CreateLink(@@)
   {
       my ($linkText, $actualParametersRef) = @_;
       my $encodedProjectName = uri_escape('$[/myJob/projectName]');
       my $encodedProcedureName = uri_escape('$[/myJob/procedureName]');
       my $actualParametersString = "";
   
       # Build the actualParameters string 
       my $paramTotal = scalar keys %$actualParametersRef;
       if ($paramTotal) {
           $actualParametersString = "&numParameters=$paramTotal";
           my $paramIndex = 1;
           foreach my $paramName (keys %$actualParametersRef) {
               my $paramValue = $actualParametersRef->{$paramName};
               $actualParametersString .= 
                               "&parameters${paramIndex}_name=$paramName".
                               "&parameters${paramIndex}_value=$paramValue";
               $paramIndex++;
           }
       }
   
       $gECommander->setProperty(
                        "report-urls/$linkText",
                        "runProcedure.php?".
                           "runNow=1". 
                           "&projectName=$encodedProjectName".
                           "&procedureName=$encodedProcedureName".
                           "$actualParametersString",
                       {"jobId" => $ENV{COMMANDER_JOBID}});
       
   }
 


avatar image By brian handley 1.6k answered Oct 24, 2012 at 11:47 PM
more ▼
(comments are locked)
avatar image mike wright Oct 25, 2012 at 01:17 AM

Fantastic, absolutely fantastic! This is exactly what I was looking for!

10|750 characters needed characters left

From the job detail page you can: - save the link to your home page by clicking on the little star on the top right corner - save the configuration of your job by clicking on the floppy icon. That will allow to run subsequents jobs with the same parameters

avatar image By lrochette 5.9k answered Oct 24, 2012 at 08:40 PM
more ▼
(comments are locked)
10|750 characters needed characters left

It looks like the UI stopped passing parameters via the URL because of URL size limitations. It was modified to instead take a reference to a job that had already run, or to a specially formatted property sheet containing parameter values. Using this new method, you would have to create a specially formatted property sheet given a job that's already run, and create a link to the runProcedure page passing a reference to that sheet.

As an example, create a project with two procedures: first and second. The goal is that when you run first, it creates a link to run the second and populates the callingJobId parameter with the jobId of the first job. Here is the command of the ec-perl step in the first job that creates the link:

use strict; use ElectricCommander; my $ec = new ElectricCommander(); my $path = '/myJob/followOn'; $ec->setProperty($path . '/numParameters', 1); $ec->setProperty($path . '/actualParameter0/actualParameterName', 'callingJobId'); $ec->setProperty($path . '/actualParameter0/value', '$[jobId]'); $ec->setProperty('/myJob/report-urls/Follow on', 'link/runProcedure/projects/$[projectName]/procedures/second?configurationPath=%2Fjobs%2F$[jobId]%2FfollowOn');

This step creates a nested sheet called followOn on the job. In that sheet, it creates a property containing the number of parameters (1 in this case). Then, for each parameter (starting with 0), it creates another nested sheet with two properties: actualParameterName and value, representing the parameter name and value respectively. The final setProperty call creates a link on the first job to run the second job, passing it a URL-encoded path to /jobs/$[jobId]/followOn.

avatar image By tanay ♦ 3.4k answered May 23, 2013 at 01:08 PM
more ▼
(comments are locked)
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.

Follow this question


Topics:

x1007
x50
x9

asked: Oct 22, 2012 at 08:17 PM

Seen: 5017 times

Last Updated: Oct 24, 2012 at 09:26 PM

Related Questions