Octopus Deploy pipeline integration

How to use Codefresh with Octopus Deploy to create, deploy, and promote releases

Octopus Deploy is a sophisticated, best-of-breed continuous delivery (CD) platform for modern software teams. Octopus offers powerful release orchestration, deployment automation, and runbook automation, while handling the scale, complexity and governance expectations of even the largest organizations with the most complex deployment challenges. Read more.

Integrating Octopus Deploy with Codefresh allows you to create, deploy, and promote releases to your Octopus Deploy environments through Codefresh pipelines.

For Octopus Deploy and Codefresh integration, you need:

  • An Octopus Deploy instance, including spaces, environments, and projects
  • An API token from your Octopus Deploy account
  • Custom Octopus Deploy steps

Our example pipeline illustrates how to use custom Octopus Deploy steps.

See Octopus Deploy instance information in Codefresh pipelines and Octopus Deploy steps in Codefresh pipelines.

You can also find these steps in the Codefresh Marketplace.

Example Codefresh pipeline with Octopus Deploy steps

The following is an example of a Codefresh pipeline that builds an application sourced from GitHub, and deploys it via Octopus Deploy.

The pipeline includes the following steps:

  • Clone the source code
  • Create a package
  • Push package to Octopus Deploy instance
  • Create a release for an existing project
  • Deploy the release
version: "1.0"

stages:
  - "build and push"
  - "deploy"

steps:
  clone:
    title: "Cloning repository"
    type: "git-clone"
    stage: "build and push"
    repo: <<YOUR REPO URL>>
    revision: "main"
    working_directory: "/codefresh/volume"
    credentials:
      username: $
      password: $

  create-package:
    title: "Create package"
    type: octopusdeploy-create-package
    stage: "build and push"
    arguments:
      ID: "Hello"
      VERSION: "1.0.0-$"
      BASE_PATH: "/codefresh/volume"
      OUT_FOLDER: "/codefresh/volume"

  push-package:
    title: "Push package"
    type: octopusdeploy-push-package
    stage: "build and push"
    arguments:
      OCTOPUS_API_KEY: $
      OCTOPUS_URL: $
      OCTOPUS_SPACE: "Spaces-42"
      PACKAGES:
        - "/codefresh/volume/Hello.1.0.0-$.zip"
      OVERWRITE_MODE: 'overwrite'

  create-release:
    type: octopusdeploy-create-release
    title: "Create release"
    stage: "deploy"
    arguments:
      OCTOPUS_API_KEY: $
      OCTOPUS_URL: $
      OCTOPUS_SPACE: "Spaces-42"
      PROJECT: "Demo Project"
      RELEASE_NUMBER: "1.0.0-$"
      PACKAGES:
       - "Hello:1.0.0-$"
      RELEASE_NOTES: This is a release note

  deploy:
    type: octopusdeploy-deploy-release
    title: "Deploy release"
    stage: "deploy"
    arguments:
      OCTOPUS_API_KEY: $
      OCTOPUS_URL: $
      OCTOPUS_SPACE: "Spaces-42"
      PROJECT: "Demo Project"
      RELEASE_NUMBER: "1.0.0-$"
      ENVIRONMENTS:
        - "Development"

Octopus Deploy instance information in Codefresh pipelines

To run Octopus Deploy steps in a Codefresh pipeline, you need the details of an existing Octopus instance, with a project, a predefined environment, and deployment process. The table describes the instance fields you need to define.

Octopus instance variable Description
OCTOPUS_URL The Octopus Server URL on which to run your Octopus Deploy steps. See Getting started with Octopus for an overview of deploy concepts.
OCTOPUS_API_KEY The Octopus Deploy API Key required for authentication. Use an existing key or create a new API key. See Creating an API Key.
OCTOPUS_SPACE The Space in which to run steps. See Spaces.
PROJECT The Octopus Deploy project to which to deploy the release. See Setting up a project.

Octopus Deploy steps in Codefresh pipelines

These are the custom Octopus Deploy steps included in the example Codefresh pipeline to create and deploy releases with Octopus Deploy. More steps that you can include are described in Optional Octopus Deploy steps in Codefresh pipelines.

Create package artifacts

Use the octopusdeploy-create-package step to create zip packages of your deployment artifacts. Specify the files to include in each package, the location of those files, and the details of the artifact to create.

Octopus Deploy Step Input parameters Output parameters
octopusdeploy-create-package
  • ID: The ID of the package to create.
  • VERSION: The version of the package in the format, "version-$, for example, "1.0.0-$".
  • BASE_PATH: The folder in which to create the package artifacts. Set to "/codefresh/volume".
  • OUT_FOLDER: The folder in which to save the artifacts, set to "/codefresh/volume".
JSON object with property Path

Push packages to Octopus Server

Use the octopusdeploy-push-package step to push packaged artifacts to the Octopus Server’s built-in repository.

Octopus Deploy Step Input parameters Output parameters
octopusdeploy-push-package
  • OCTOPUS_URL, OCTOPUS_API_KEY, and OCTOPUS_SPACE: The Octopus instance details to add to the step as variables.
  • PACKAGES: The package or list of packages to push to the built-in repository. For example, "/codefresh/volume/Hello.1.0.0-$.zip".
  • OVERWRITE_MODE: Set to overwrite to replace existing packages with the same names with the package or packages in PACKAGES.
N/A

Create a release

Use the octopusdeploy-create-release step to create a release for a project.

Octopus Deploy Step Input parameters Output parameters
octopusdeploy-create-release
  • OCTOPUS_URL, OCTOPUS_API_KEY, and OCTOPUS_SPACE: The Octopus instance details to add to the step as variables.
  • PROJECT: The project for which to create the release. For example, "Demo Project".
  • RELEASE_NUMBER: Optional. The version of the release, which is concatenated from the release version and the variable.
  • PACKAGES: Optional. The name of the package or list of packages to include in the release. The format is "<release-name>:<release-version>-$".
JSON object with the Channel and Version for the release.

Deploy a release

Use the octopusdeploy-deploy-release step to deploy a release. If needed, provide optional parameters to specify guided failure mode and variables.
For a tenanted release, see Deploy a tenanted release.

Octopus Deploy Step Input parameters Output parameters
octopusdeploy-deploy-release
  • OCTOPUS_URL, OCTOPUS_API_KEY, and OCTOPUS_SPACE: The Octopus instance details to add to the step as variables.
  • PROJECT: The project for which to deploy the release. For example, "Demo Project".
  • RELEASE_NUMBER: Optional. The version of the release, which is concatenated from the release version and the {CF_BUILD_ID}} variable.
  • ENVIRONMENTS: Required. The name of the predefined environment or list of environments to which to deploy the release. For example, "Development".
JSON array of deployments created, each with DeploymentId and ServerTaskId.

Optional Octopus Deploy steps in Codefresh pipelines

Deploy a tenanted release

To deploy a tenanted release, use the octopusdeploy-deploy-release-tenanted step. Define the tenants to deploy to using either tenants or tenant tags.
For an untenanted release, see Deploy a release.

Customize the deployment of the tenanted release with prompted variable values, tenants, tenant tags, and guided failure mode. This step returns a json array of created deployments, with properties DeploymentId and ServerTaskId.

Run a runbook

To run a runbook, use the octopusdeploy-run-runbook step.

The step requires the name of the runbook to run, the project and environment name(s). Optional arguments include variables to use within the runbook, the option to run for specific tenants or tenant tags, as well as the option to use guided failure mode.

The step returns a JSON array of created runbook runs, with properties RunbookRunId and ServerTaskId.

Push build information

To push build information for a project, use the octopusdeploy-push-build-information step. Provide a list of packages that need build information, a build information json file and a version number.

By default, if build information already exists the step will fail. You can change the default behavior by changing OVERWRITE_MODE from fail to overwrite or ignore.

Sample build information JSON file:

{
  "BuildEnvironment": "BitBucket",
  "Branch": "main",
  "BuildNumber": "288",
  "BuildUrl": "https://bitbucket.org/octopussamples/petclinic/addon/pipelines/home#!/results/288",
  "VcsType": "Git",
  "VcsRoot": "http://bitbucket.org/octopussamples/petclinic",
  "VcsCommitNumber": "12345",
  "Commits":
  [
    {
      "Id": "12345",
      "Comment": "Sample commit message"
    }
  ]
}

This step has no output.

Steps in pipelines
Variables in pipelines
Marketplace: Octopus Deploy Create package
Marketplace: Octopus Deploy Push package
Marketplace: Octopus Deploy Create release
Marketplace: Octopus Deploy Deploy release
Marketplace: Octopus Deploy Deploy tenanted release
Marketplace: Octopus Deploy Run a runbook
Marketplace: Octopus Deploy Push build information