03-23-2016 12:39 PM - edited 03-01-2019 06:41 AM
Task Name | Powershell Exit code check |
Description | |
Prerequisites |
|
Category | Workflow |
Components | vSphere 5.x |
User Inputs |
Instructions for Regular Workflow Use:
Thank you Tejeswar Sahu
The workflow
The tasks
The error check
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.
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
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...
I just ran it with following test...
Power shell task:
Output to input mapping:
Workflow run:
Input output values:
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
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);
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)
Yes. The code in my last reply is right after the Start-Job.
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.
Your example works for me. Not sure why it breaks when running a script with Start-Job.
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)
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: