Check if step succeeded with warning

When checking the status of a step, is it possible to check if there were any warnings?

I’ve visited the System Variables page, but I can’t seem to find anything that will help.

If I have one step that simply outputs a warning…

Write-Warning "Oh dear, something is not quite right."

And then another that outputs the status of that step…

Write-Host "Status: #{Octopus.Step[Run a Script].Status.Code}"
Write-Host "Error: #{Octopus.Step[Run a Script].Status.Error}"
Write-Host "ErrorDetail: #{Octopus.Step[Run a Script].Status.ErrorDetail}"

The output I see is as follows, which means I can’t use Octopus.Step.Status.Code to check if a warning occurred.

Status: Succeeded
Error: #{Octopus.Step[Run a Script].Status.Error}
ErrorDetail: #{Octopus.Step[Run a Script].Status.ErrorDetail}

It seems that the UI uses the tasks API to query the server task that ran the deployment, which notes "HasWarningsOrErrors": true. However, I can’t see any way of getting that information through system variables, and obviously I’d prefer not to have to query the tasks API myself as part of the deployment (if that’s even possible before the task has finished?!).

Hopefully I’m missing something?

Thanks,
David

Hi David,

You are correct. The only way to know that step completed with warnings is to query the tasks API. Depending on your situation, you could set the OctopusTreatWarningsAsErrors setting to True or use an Output variable to check in subsequent steps, as alternatives. Otherwise, querying the tasks API is the best route to go.

Thanks,
Mark

HI Mark,

Thanks for the reply.

Unfortunately I can’t treat warnings as errors. I need the deployment to stop if there are errors in step A, but continue if there are warnings, albeit skipping step B.

I’m open to setting an output variable, but does the same issue not exist there? How can I check the current step for warnings, other than manually checking the response of each command, which would be hard work in this case?

Thanks,
David

Hi David,

I understand. Without knowing your specific process, if your Step A is a script step which runs several commands, then yes, you would need some process to check the result of each command in order to set an output variable appropriately. If that is too much work in your situation, then having a step after Step A which calls the tasks API, checks that step for warnings, and then sets an output variable for your following conditional steps may be the best route to go.

I hope this helps, and let me know if you have further questions.

Thanks,
Mark

Hi Mark,

The additional step would work, but I want to avoid having to call the API as part of the deployment process, as it would mean creating and managing a token.

In my case, I need to know if a Terraform state was destroyed without warning, so I can run terraform show to ensure that there is nothing left to delete. Not ideal, but it works.

Thanks,
David

Hi David,

If you want to avoid calling the API, then you are left with checking that terraform destroy command for warnings and setting an output variable that you can use in that subsequent terraform show step.

If you do decide to go the API route, you could consider expiring tokens and using a runbook to create new ones which it then stores in a sensitive variable. That might help with the management of them, but if you still want to avoid them, then yes, you are left with that output variable process at this time.

Thanks,
Mark