Mark a step not to mark deployment as Failed?

Hi

I was wondering if there is a way to make certain steps not mark the build as Failed, without using the guided failure?

I have a few deployments and they all email out and also post into HipChat when done but every now and then the connection to either the mail server or HipChat times out and then the whole entire build gets marked as Failed.

This is a problem because these deployments are in the middle of TeamCity config which then wants to do some tests when the code is deployed but because Octopus says it’s failed, TeamCity stops deploying/building/testing even though the deploy steps of Octopus works.

Thanks
Gavin

P.S. I say without using guided failure as TeamCity has a timeout on Octopus of 10 minutes so I’m not always able to fix the release in time (lunch, evening, nights, weekends, AFK etc…)

Hi Gavin,

Thanks for reaching out. This is not possible without using guided failure. What you could do though is build you own email and hipchat steps with Powershell adding some sort of retry-timeout logic when this happens. Or a try-catch block that catches the error when it happens, and still returns an exit code of 0 so Octopus believes everything went ok.

Hope that helps,

Dalmiro

Hi Dalmiro

Thanks very much for this, the HipChat step is a custom step so that will be easily amendable to add a try catch with the catch just returning 0.

I’ll need to find/make the same for the email but you can mark this as resolved.

Thanks for the help.
Gavin

Hi Gavin,

For the email message you could use this Powershell cmdlet: https://technet.microsoft.com/en-us/library/hh849925.aspx

Here’s a retry function we use frequently on our step templates:

$maxFailures = 5
$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4
function Execute-WithRetry([ScriptBlock] $command) {
	$attemptCount = 0
	$operationIncomplete = $true

	while ($operationIncomplete -and $attemptCount -lt $maxFailures) {
		$attemptCount = ($attemptCount + 1)

		if ($attemptCount -ge 2) {
			Write-Output "Waiting for $sleepBetweenFailures seconds before retrying..."
			Start-Sleep -s $sleepBetweenFailures
			Write-Output "Retrying..."
		}

		try {
			& $command

			$operationIncomplete = $false
		} catch [System.Exception] {
			if ($attemptCount -lt ($maxFailures)) {
				Write-Output ("Attempt $attemptCount of $maxFailures failed: " + $_.Exception.Message)
			
			}
			else {
			    throw "Failed to execute command"
			}
		}
	}
}

Check this template for a usage example: https://library.octopusdeploy.com/#!/step-template/actiontemplate-iis-apppool-create

Hope that helps!

Dalmiro