skip to Main Content

So i have two steps in Octopus Deploy. first step will deploy the cluster and task definition and the other will update the task definition and deploys a new task. The First step is only needed for the first time.. how do i skip the step with run conditions.

2

Answers


  1. Chosen as BEST ANSWER

    turns out i can update the existing service using Deploy AWS ECS Service steps itself.Just takes a really long time to deploy. cheers....!


  2. EDIT: Updated to better reflect the way the Octopus Deploy an ECS Service and Update an ECS Service steps work.

    Typically, I wouldn’t expect to see both the Deploy an ECS service step and the Update an ECS Service step in the same Octopus deployment or runbook process.

    The reason being is that the Deploy an ECS service step creates a service and task for you from scratch in a cloud formation stack that Octopus then manages – it helps you get started with ECS if you haven’t got something running in there already.

    Conversely, you’d tend to use the update an ECS service step when the service and task already exist, and you want to deploy new versions of the task (new container images) over time. The cluster may be managed with a tool like terraform or by hand.

    You’d, therefore, only need to use one or the other step, not both, as the deploy an ECS service step will update a previously deployed (by Octopus) ECS service if it exists.

    If you really need to use both, then one option is to use a new step, that would be placed to run before the "first" and "second" step from your scenario.

    This new step would likely be a run an AWS CLI script step. With it, you can use one of the ecs commands, probably list-services, to see if the service with the specified name already exists in the cluster.

    When you know if the service exists or not, the step would then make use of an octopus output variable. You set it (assuming PowerShell script step) like so:

    # Set to true if it exists
    Set-OctopusVariable -name "ECSServiceExists" -value "True"
    # OR False if it doesnt
    Set-OctopusVariable -name "ECSServiceExists" -value "False"
    

    Then for your "first" step that creates the service, you’d set a variable run condition to something like this:

    #{unless Octopus.Deployment.Error}#{RunIfServiceDoesntExist}#{/unless}
    

    The condition is doing two things:

    1. Only running when there isn’t a general error in the deployment (indicated by Octopus.Deployment.Error
    2. Testing a new project variable called RunIfServiceDoesntExist to see if that evaluates to true.

    For the condition to work, you need to create a new RunIfServiceDoesntExist project variable with value:

    #{if Octopus.Action[Check for ECS Service].Output.ECSServiceExists == "False"}true#{/if}
    

    Note: Replace Check for ECS Service with the name you give the new step to test for the ecs service’s existence.

    You can have the if condition above directly in the run condition itself, but I find the project variable hides away the complexity a little and makes it easier to read.

    Hope that helps!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search