cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2316
Views
1
Helpful
9
Comments
Orf Gelbrich
Cisco Employee
Cisco Employee
Task NamePowershell Exit code check
Description
Prerequisites
  1. Tested on 5.4
CategoryWorkflow
ComponentsvSphere 5.x
User Inputs

Instructions for Regular Workflow Use:

  1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
  2. Unzip the file on your computer. Should end up with a .WFD file.
  3. Log in to UCS Director as a user that has "system-admin" privileges.
  4. Navigate to "Policies-->Orchestration" and click on "Import".
  5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
  6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
  7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
  8. Click "Submit".
  9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

Thank you Tejeswar Sahu

The workflow

Unknown.png

The tasks

Unknown-1.png

The error check

Unknown-2.png

The task has  been failed as we are pinging to an invalid ip address.

The idea is we are failing a task based on the execution status of the execution of a command.

Comments
danielkeisling
Community Member

I get the error:

(custom_Powershelltask status) failed with error - java.lang.Exception: Powershell task failed in <eval> at line number 46 at column number 1, selectedContext=<None>

I am mapping the Powershell Output to previous task's POWERSHELL_COMMAND_RESULT.  In the previous task, I have this in the last three lines:

Start-Job -FilePath "C:\\scripts\\script1.ps1" -ArgumentList $arg1 | Wait-Job | Receive-Job

$?

$LASTEXITCODE;

Any ideas?


Thanks!

Daniel

Orf Gelbrich
Cisco Employee
Cisco Employee

I downloaded the task and assuming your custom task still looks like the original and line 46 still looks the same then it would be good to have the out put for the logger above to draw any sort of conclusion...

Screen Shot 2016-12-13 at 8.22.36 AM.png

Orf Gelbrich
Cisco Employee
Cisco Employee

I just ran it with following test...

Power  shell task:

Screen Shot 2016-12-13 at 8.42.36 AM.png

Output to input mapping:

Screen Shot 2016-12-13 at 8.42.47 AM.png

Workflow run:

Screen Shot 2016-12-13 at 8.42.25 AM.png

Input output values:

Screen Shot 2016-12-13 at 8.42.13 AM.png

Service Request ID: 8612

Workflow Inputs:

- Password

Dec 13, 2016 14:35:45 UTC Request submitted

Dec 13, 2016 14:35:50 UTC Executing workflow item number 1

Dec 13, 2016 14:35:50 UTC Completed workflow item number 1, with status Completed

Dec 13, 2016 14:35:58 UTC Executing workflow item number 2

Dec 13, 2016 14:35:58 UTC Trigger context executeWorkFlowStep called

Dec 13, 2016 14:35:58 UTC Executing custom action Junk (Execute PowerShell Command)

Dec 13, 2016 14:35:58 UTC Executing custom action Junk (Execute PowerShell Command)

Dec 13, 2016 14:36:00 UTC Max wait time min milli seconds = 300000

Dec 13, 2016 14:36:01 UTC executor finished.....true

Dec 13, 2016 14:36:01 UTC Command executed successfully.

Dec 13, 2016 14:36:02 UTC Task #2 (Junk (Execute PowerShell Command)) completed successfully in 4 seconds

Dec 13, 2016 14:36:02 UTC Input/Output values for Task #2 (Junk (Execute PowerShell Command)):

Dec 13, 2016 14:36:02 UTC [Local Input: Label = t1]

Dec 13, 2016 14:36:02 UTC [Local Input: PowerShell Agent = DallasMainServer]

Dec 13, 2016 14:36:02 UTC [Local Input: Target Machine IP = 172.17.32.110]

Dec 13, 2016 14:36:02 UTC [Local Input: User ID = administrator]

Dec 13, 2016 14:36:02 UTC [Local Input: Password = **masked-value**]

Dec 13, 2016 14:36:02 UTC [Local Input: Domain = ciscodemo.local]

Dec 13, 2016 14:36:03 UTC [Local Input: Commands/Script = echo 'ABC' > c:\abc12132016.txt $? $LASTEXITCODE;]

Dec 13, 2016 14:36:03 UTC [Local Input: Commands/Rollback Script = ]

Dec 13, 2016 14:36:03 UTC [Local Input: Output Format = XML]

Dec 13, 2016 14:36:03 UTC [Local Input: Depth = 1]

Dec 13, 2016 14:36:03 UTC [Local Input: Maximum Wait Time = 5]

Dec 13, 2016 14:36:03 UTC [Output: POWERSHELL_COMMAND_RESULT = <?xml version='1.0'?><Objects><Object Type='System.Boolean'>True</Object><Object /></Objects>Command successful]

Dec 13, 2016 14:36:03 UTC Completed workflow item number 2, with status Completed

Dec 13, 2016 14:36:05 UTC Executing workflow item number 3

Dec 13, 2016 14:36:05 UTC Trigger context executeWorkFlowStep called

Dec 13, 2016 14:36:05 UTC Executing custom action Junk (custom_Powershelltask status)

Dec 13, 2016 14:36:05 UTC Executing custom action Junk (custom_Powershelltask status)

Dec 13, 2016 14:36:05 UTC Executing custom script for Powershelltask status

Dec 13, 2016 14:36:08 UTC Command executionStatus True

Dec 13, 2016 14:36:08 UTC Exit code 0

Dec 13, 2016 14:36:10 UTC Processing output: exit_code

Dec 13, 2016 14:36:10 UTC output: exit_code is not set

Dec 13, 2016 14:36:10 UTC Processing output: status

Dec 13, 2016 14:36:10 UTC output: status is not set

Dec 13, 2016 14:36:10 UTC Task #3 (Junk (custom_Powershelltask status)) completed successfully in 5 seconds

Dec 13, 2016 14:36:10 UTC Input/Output values for Task #3 (Junk (custom_Powershelltask status)):

Dec 13, 2016 14:36:10 UTC [Mapped Input: Powershell Output = <?xml version='1.0'?><Objects><Object Type='System.Boolean'>True</Object><Object /></Objects>Command successful]

Dec 13, 2016 14:36:10 UTC [Output: status = True]

Dec 13, 2016 14:36:10 UTC [Output: exit_code = 0]

Dec 13, 2016 14:36:10 UTC Completed workflow item number 3, with status Completed

Dec 13, 2016 14:36:12 UTC Executing workflow item number 4

Dec 13, 2016 14:36:12 UTC Completed workflow item number 4, with status Completed

danielkeisling
Community Member

Adding that logging in the powershell tasks results in another error:

(Execute PowerShell Command) failed with error - Command failedError while executing command: java.lang.Exception: Error code: 3, error message: Exception while executing script, selectedContext=<None>

Dec 13, 2016 15:38:11 UTC Task #3 (Proteus Beta Tests (Execute PowerShell Command)) failed after 0 seconds

Here's the code:


$?

$LASTEXITCODE;

logger.addInfo("Command executionStatus "+executionStatus);

logger.addInfo("Exit code "+exitCode);

//output.exit_code = exitCode;

//output.status = executionStatus;

ctxt.saveOutputValue("status",executionStatus);

ctxt.saveOutputValue("exit_code",exitCode);

Orf Gelbrich
Cisco Employee
Cisco Employee

You added the Java script to the power shell task?

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

danielkeisling
Community Member

Yes.  The code in my last reply is right after the Start-Job.

Orf Gelbrich
Cisco Employee
Cisco Employee

Powershell will run powershell commands.  Poweshell does not understand java script code within powershell.

I was looking for the output in the SR log.

Did you try my example and see if that worked for you?  All the screen shots I took in above reply.

danielkeisling
Community Member

Your example works for me.  Not sure why it breaks when running a script with Start-Job.

Orf Gelbrich
Cisco Employee
Cisco Employee

The logger (SR log) could potentially give an answer..

Orf Gelbrich

Check out UCS Director Workflow INDEX<https://communities.cisco.com/docs/DOC-56419> on Cisco Communities Site (Twitter @UCSDGURU)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links