The powershell script in runbook is executing on hybrid worker and errors out when the file is not found. But when called through ADF webhook, the activity passes. Can someone me tell how to capture the error in ADF?
SCRIPT:
param(
[Parameter (Mandatory = $false)]
[object] $WebhookData
)
Import-Module Az.Storage -force
if($WebhookData){
$parameters=(ConvertFrom-Json -InputObject $WebhookData.RequestBody)
if($parameters.callBackUri) {$callBackUri=$parameters.callBackUri}
}
TRY
{
$connectionName = ***************
$storageAccountName = *****************
$sasToken = ************************
$context = New-AzStorageContext -StorageAccountName $storageAccountName -SASToken $sasToken
$localFile = "C:\VenaIntegrate\Data\In\"
$filename = "exporthierarchy" + (Get-Date -format "yyyyMMdd") + ".psv"
$filename2 = "exportattributes" + (Get-Date -format "yyyyMMdd") + ".psv"
$path = $localFile + $filename
$path2 = $localFile + $filename2
$filesystemName = ******
Set-AzStorageBlobContent -File $path -Container $filesystemName -Context $context -Force
Set-AzStorageBlobContent -File $path2 -Container $filesystemName -Context $context -Force
}
CATCH {
Write-Error "Error Occured"
$callBackUri = $parameters.callBackUri
# Create an error message
# Message and statuscode will show up in ADF
$body = [ordered]@{
error = @{
ErrorCode = "Error Occured"
Message = "File not found"
}
statusCode = "404"
}
# Convert the string into a real JSON-formatted string
$bodyJson = $body | ConvertTo-Json
# Call back with error message in body and a JSON contenttype
Invoke-WebRequest -UseBasicParsing -Uri $callBackUri -Method Post -Body $bodyJson -ContentType "application/json"
}
#$callBackUri = $parameters.callBackUri
If (!$callBackUri)
{
# Create an error message
# Message and statuscode will show up in ADF
$body = [ordered]@{
error = @{
ErrorCode = "ParameterError"
Message = "Required parameters where not provided"
}
statusCode = "404"
}
# Convert the string into a real JSON-formatted string
$bodyJson = $body | ConvertTo-Json
# Call back with error message in body and a JSON contenttype
Invoke-WebRequest -UseBasicParsing -Uri $callBackUri -Method Post -Body $bodyJson -ContentType "application/json"
}
else
{
$body = [ordered]@{
success = @{
SuccessCode = "Process success"
Message = "Process completed successfully"
}
}
# Convert the string into a real JSON-formatted string
$bodyJson = $body | ConvertTo-Json
# Call back with error message in body and a JSON contenttype
Invoke-WebRequest -UseBasicParsing -Uri $callBackUri -Method Post -Body $bodyJson -ContentType "application/json"
}
Even though the runbook fails in the automation account, it succeeds in ADF when called through runbook saying "No output available. You can specify webhook activity output by setting output property in request body of callback"