x
login Signup

How to use a stored credential for impersonation in a dynamically created jobStep?

Please provide an ec-perl example with the steps involved. Thanks!

avatar image By jirwin 15 asked Mar 06 at 06:15 PM
more ▼
(comments are locked)
avatar image jirwin Feb 24 at 05:12 PM

After several attempts calling the createJobStep API with different credential and credentialName parameters, and NOT seeing runAsUser set in the resulting step details I realized that the step is running with the correct credential but apparently runAsUser does not get set. So my question now.. Is this a bug? Is there some other way to set runAsUser in step details for a dynamically created step? Thx..

10|750 characters needed characters left

1 answer: sort voted first

The following DSL illustrates how to do this:

 project "Test2", {
     credential "vagrant", userName: "vagrant", password: "vagrant"
     procedure "Job to run",{
             step "step to run", command: 'echo $USER'
         }
     procedure "Create Jobs steps", {
         step "No impersonation", shell: "ec-perl", command: '''\
             use ElectricCommander;
             $| = 1;
             my $batch = new ElectricCommander();
             $batch->createJobStep({ 
                 subproject=> 'Test2',
                 subprocedure => 'Job to run',
             })
         '''.stripIndent()
         step "With impersonation", shell: "ec-perl", command: '''\
             use ElectricCommander;
             $| = 1;
             my $batch = new ElectricCommander();
             $batch->createJobStep({ 
                 subproject=> 'Test2',
                 subprocedure => 'Job to run',
                 credentialName => 'vagrant'
             })
         '''.stripIndent()
     } // procedure
 } // project

The exported jobStep file includes the line:

     <runAsUser>vagrant</runAsUser>
avatar image By gregm 2k answered Apr 27 at 01:33 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.