VSTS Online Build with Octopus Deploy - Channel based release & deploy

Hello -

We are using Octopus Deploy with VSTS Online Build. We have feature based branching and each feature should be deployed on its own DEV environment. So we are trying to use Channels in Octopus to do that. In the VSTS Build Definition, we are using “Create Octopus Release” task to create the release and we provide the channel name which is the same as the branch name but we don’t specify the environment to deploy. This way we can use the same build definition and same Octopus project for all the feature branches. This is working fine except for one caveat, VSTS build definition is not aware of the actual deployment of the release. If fact, VSTS build completes successfully after creating just the release and it does not wait for the Octopus to complete the deployment of the release. So even if the deployment was failed for some reason, VSTS build shows successful. Is there anyway to overcome this? Am I doing it the right way?

Thanks,
Jignesh

Hi Jignesh,

Thanks for reaching out! Did you check the “Show Deployment Progress” box(see attached screenshot)?

When checked, your build will synchronously report everything that’s happening during the deployment and fail if the deployment fails.

Regards,
Dalmiro

Hi Dalmiro -

I couldn’t find the screenshot you attached here. But if you are mentioning the one which I have shown in the attached screenshot then yes, it is checked. But that only works when I have specified the environment. Even I tries passing the “–waitfordeployment” additional octo.exe argument but that doesn’t work either.

Thanks,
Jignesh

Sorry, I forgot to attach the screenshot! Yes I was talking about that checkbox.

But that only works when I have specified the environment

That’s correct. You need to specify and Environment to execute the deployment from the VSTS build.

This is working fine except for one caveat, VSTS build definition is not aware of the actual deployment of the release.

From what I understand, you are creating the release from your VSTS build. But how are you triggering the deployment of that release once it gets created? Are you doing it from a VSTS step? or do you have your lifecycle configuration in Octopus triggering the deployment for you?

The only way to keep a synchronous relationship between your build and your deployment (so if the latter fails, the build also fails) is by running the deployment from the build with the Show Deployment Progress box checked. And to do that you need to specify the Environment on that field.

how are you triggering the deployment of that release once it gets created? Are you doing it from a VSTS step? or do you have your lifecycle configuration in Octopus triggering the deployment for you?

I am specifying which channel to use. And inside channel’s lifecycle’s environment, I have setting to deploy automatically.

Is there any other way to find out if the deployment was complete for this release? like using any api?

Hi Jignesh,

You can do it using the API, but I must warn you that this would add some unnecessary overhead to your build process. That Show deployment progress checkbox was created for this exact purpose.

The above warning said, I’d recommend you to use the open source project Octoposh which has a cmdlet called Get-OctopusDeployment which will return an object that looks like this:

ProjectName         : Powershell1
EnvironmentName     : Development
DeploymentStartTime : 08/06/2017 4:23:44 PM
DeploymentEndTime   : 
DeploymentStartedBy : dalmiro.granias@NY.local
Id                  : Deployments-3881
Duration            : 00:00:10
Status              : Executing
ReleaseVersion      : 0.0.59
ReleaseCreationDate : 08/06/2017 4:23:38 PM
ReleaseNotes        : MyNotes
ReleaseCreatedBy    : dalmiro.granias@NY.local
Packages            : {}
Resource            : Octopus.Client.Model.DeploymentResource

You could run that cmdlet in a loop until status is not equal to executing.

Hope that helps,
Dalmiro

I am trying to use that cmdlet, but if I execute this command while the deployment is in progress it throws below error. But after the deployment is completed I get Success in status. Any idea what I might be doing wrong?

System.Management.Automation.CmdletInvocationException: Nullable object must have a value. —> System.InvalidOperationException: Nullable object must have a value.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Nullable1.get_Value() at Octoposh.Model.OutputConverter.GetOctopusDeployment(List1 baseResourceList, List1 environments, List1 projects, List1 releases) at Octoposh.Cmdlets.GetOctopusDeployment.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() --- End of inner exception stack trace --- at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate) at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext) at System.Management.Automation.Interpreter.ActionCallInstruction6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Thanks in advance for your support here.
Jignesh desai
Software Engineer Principal, Technology

[cid:image002.png@01D2EC19.9CE8B680]

3701 regent blvd | Irving, TX 75063
O: (469) 346-4615 | M: (720) 278-5976
jignesh.desai@CaliberHomeLoans.commailto:jignesh.desai@CaliberHomeLoans.com
www.CaliberHomeLoans.comhttp://www.caliberhomeloans.com/

image001.png

image002.png

I think the line number 383 could be causing this error as I am getting this error while the deployment is in progress and it will not have the value in CompletedTime and hence accessing the Value property would through this error. What do you think? Any workaround or I’ll have to wait till it is fixed?

Thanks for submitting that bug! I’m working on it right now and will try to ship the fix today.

GH issue you can follow: https://github.com/Dalmirog/OctoPosh/issues/281

Hi,

Sorry for the terrible delay here. I’ve published Octoposh 0.6.10 with the fix for this

http://octoposh.net/

Thanks!
Dalmiro

I am out of office returning on 7/10 with very limited access to email. I will try to reply as soon as I can. For any immediate assistance please contact Deepak Vij.

Thanks,
Jignesh Desai
720.278.5976

We care about our customer’s personal information. Please contact the appropriate parties to verify any emails requesting personal/financial information or requesting funds to be wired, prior to taking any action.


This electronic transmission and any documents or other writings sent with it constitute confidential information, which is intended only for the named recipient. If you are not the intended recipient, please reply to the sender that you have received the message in error and delete it. Any disclosure, copying, distribution or the taking of any action concerning the contents of this communication or any attachment(s) by anyone other than the intended recipient is strictly prohibited. Caliber Home Loans, Inc. 3701 Regent Blvd., Suite 200, Irving, TX 75063. Equal Housing Lender. NMLS # 15622

Thank you!

Regards,
Jignesh