Created
March 26, 2015 11:21
-
-
Save trondhindenes/41c9b38e434673d9a62d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Workflow Dummy-WFInner | |
{ | |
Param ( | |
[Parameter(Mandatory=$true)] | |
[PsCredential]$credential, | |
[Parameter(Mandatory=$true)] | |
[String]$subscriptionid, | |
[Parameter(Mandatory=$true)] | |
[string]$DevenvId | |
) | |
#Set up stuff | |
$ErrorActionPreference = "Stop" | |
$verbosePreference = "Continue" | |
Write-Verbose "Starting workflow Dummy-WFInner" | |
#Create output object | |
$OutObject = [PSCustomObject]@{} | |
#All real work goes into a try block | |
try | |
{ | |
$somestuff = Get-AutomationVariable -name "Somestuff" | |
#Real work goes here | |
InlineScript { | |
#or here | |
} | |
#returning results from InlineScript (make sure the code is "muted", e.g. it doesnt output unwanted stuff to stdout | |
$InlineScriptResult = InlineScript { | |
#or here | |
} | |
#The outobject can also be used for sending non-error data up to the parent | |
add-member -InputObject $OutObject -MemberType NoteProperty -Name InlineScriptResult -Value $InlineScriptResult -Force | |
} | |
Catch | |
{ | |
$errormessage = $_ | |
#Comment out this line if you dont want the inner wf to print errordata to the verbose stream | |
#$errormessage | Write-Verbose | |
#Add stuff | |
add-member -InputObject $OutObject -MemberType NoteProperty -Name error -Value $errormessage -Force | |
if ($errormessage.errorRecord) | |
{ | |
add-member -InputObject $OutObject -MemberType NoteProperty -Name ErrorCommand -Value $errormessage.errorRecord.InvocationInfo.MyCOmmand.Name -Force | |
} | |
#Breaking means that the wf didnt suceed | |
Write-Verbose "Breaking workflow Dummy-WFInner" | |
} | |
$OutObject | |
Write-Verbose "Ending workflow Dummy-WFInner" | |
} | |
Workflow Dummy-WfOuter | |
{ | |
Param ( | |
[Parameter(Mandatory=$true)] | |
[PsCredential]$credential, | |
[Parameter(Mandatory=$true)] | |
[String]$subscriptionid, | |
[Parameter(Mandatory=$true)] | |
[string]$DevenvId | |
) | |
#Set up stuff | |
$ErrorActionPreference = "Stop" | |
$verbosePreference = "Continue" | |
Write-Verbose "Starting workflow Dummy-WfOuter" | |
$DummyResultt = Dummy-WFInner -param1 $true -param2 $something | |
if ($DummyResultt.error -ne $null) | |
{ | |
#Print the error from inner, and report to external system or whatever | |
Write-Verbose "Error reported by $($DummyResultt.ErrorCommand): $($DummyResultt.error)" | |
Write-Output "Breaking the workflow." | |
return | |
} | |
Write-Verbose "Ending workflow Dummy-WfOuter" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment