OctopusDeploy Integration with StackStorm

October 1, 2015
Guest post by Anthony Shaw, Head of Innovation, ITaaS at Dimension Data

This blog post will take you through the integration pack for OctopusDeploy and give you some example actions and rules to integrate with other packs.

What is OctopusDeploy?

Octopus Deploy is an automated deployment tool for .NET and Windows environments. It has gained significant popularity amongst the .NET development community for it’s ease of use and integration into the Microsoft development ecosystem. OctopusDeploy enables users to automate deployment of applications, packages and tools to Windows environments.

Why integrate OctopusDeploy into StackStorm?

Octopus Deploy provides a rich system for Windows application deployments, but this is typically part of a wider DevOps process. Unlike StackStorm, it does not support closed-loop monitoring, remediation or infrastructure configuration and building, it does not integrate into configuration management tools (nor claim to). If you want to integrate OctopusDeploy from another tool, as part of a DevOps or environment tool you could write custom integrations from each tool to the Octopus API or you could simply use StackStorm as the go-between to join your systems together. Imagine the possible integration scenarios:

  • Configuring the Octopus Deploy agent as part of a new environment creation
  • Creating a new release when a git commit is detected
  • Calling a 3rd party system when a release or deployment is created in Octopus

The Octopus Deploy pack for StackStorm enables you to drive those scenarios with no additional development. StackStorm packs consist of 2 components:

  • Actions – Tasks that can be called from a trigger, e.g. “Create Release”
  • Sensors – Processes that run and detect events as triggers, e.g. “New Release”

Supported Actions The following actions listed below are supported:

  • Create a new release – create_release
  • Deploy a release to an environment – deploy_release
  • Get a list of releases for a project – get_releases
  • Add a new machine to an environment(s) – add_machine

Sensors Actions or workflows can be initialized automatically from these sensors:

  • Detect a new release being created – new_release_sensor
  • Detect a new deployment being created – new_deployment_sensor

Installing the OctopusDeploy integration pack

From the StackStorm console, use the packs.install task to download and install the pack:

st2 pack install octopusdeploy

StackStorm packs by convention each have a configuration file for server-wide properties. The Octopus pack needs to be configured first, update /opt/stackstorm/packs/octopusdeploy/config.yaml to setup the connection to Octopus. You need to issue an Octopus Deploy API key to integrate the pack. The documentation for this is available on the Octopus Website. Within config.yaml, populate the example properties with your test instance

  • api_key – an API key generated in Octopus for your user
  • host – the hostname of your Octopus server e.g. octopus.mydomain.com
  • port – the port your API service is running on, 443 by default Now, restart the StackStorm services to reload the configurationst2ctl restart

Now you can test in the UI to get releases and versions. Select the actions pane and choose get_releases. Enter the project ID of one of your existing projects and execute the action.

Screenshot of Octopus Integration

A real life example

Got it? Ok, lets look at a more concrete example. Let’s create a basic rule that detects when a new release or deployment is raised and posts a message in Slack with some details. I’m going to assume you already have a Slack account, if you haven’t already installed the Slack pack you can do so now

st2 pack install slack

Then update /opt/stackstorm/configs/slack.yaml with an authentication token from Slack using the instructions here.

From the console, create a new rule definition using this format:

{
   "name": "octopus_releases",
   "tags": [],
   "enabled": true,
   "trigger": {
       "type": "octopusdeploy.new_release",
       "parameters": {},
       "pack": "octopusdeploy"
    },
   "criteria": {},
   "action": {
       "ref": "slack.post_message",
       "parameters": {
           "username": "anthonypjshaw",
           "message": "{{trigger.author}} created a release {{trigger.version}} in octopus project {{trigger.project_id}} with notes {{trigger.release_notes}}",
           "channel": "#releases"
       } 
   }, 
   "pack": "octopusdeploy"
}

Import the rule into StackStorm by using the rule create command.

st2 rule create release_rule.json

Back in the UI you will see your new rule,

Completed Rule

When someone has created a new release, you will see the rule action in the History pane:

Run history

To detect new deployments, create a new rule

{
    "name": "octopus_deployments",
    "tags": [],
    "enabled": true,
    "trigger": {
         "type": "octopusdeploy.new_deployment",
         "parameters": {},
         "pack": "octopusdeploy"
    },
    "criteria": {},
    "action": {
          "ref": "slack.post_message",
          "parameters": {
                  "username": "anthonypjshaw",
                  "message": "{{trigger.author}} created a deployment {{trigger.version}} in octopus project {{trigger.project_id}}",
                  "channel": "#releases"
          }
    },
    "pack": "octopusdeploy"
}

And then in Slack you should see a live feed of new releases and deployments within the “Releases” channel.

slack view

What’s next

Now you’re familiar with the pack and the potential for other integration scenarios, check out some of the other actions you could run in packs like:

  • Ansible, Salt, Chef, Puppet – Combining your Octopus workflows with other devops tools
  • Git, GitHub, Jenkins – Triggering new releases or deployments from build or source control events
  • AWS, Azure, LibCloud – Deploying Octopus tentacles as part of your infrastructure standup
  • Twitter – Want to automatically announce new releases of your product to the world?!