go-octopusdeploy

module
v2.77.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2025 License: Apache-2.0

README

go-octopusdeploy Logo

go-octopusdeploy

Go API Client for Octopus Deploy 🐙

GitHub release PkgGoDev Go Report


Install

go get "github.com/OctopusDeploy/go-octopusdeploy/v2"

Usage

import "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"

The Octopus REST API is exposed through service fields of the client. An API key is required to communicate with the API (see How to Create an API Key for more information).

apiKey := "API-YOUR_API_KEY"
octopusURL := "https://your_octopus_url"
spaceID := "space-id" // can also be blank to assume the default space

apiURL, err := url.Parse(octopusURL)
if err != nil {
    _ = fmt.Errorf("error parsing URL for Octopus API: %v", err)
    return
}

// the first parameter for NewClient can accept a http.Client if you wish to
// override the default; also, the spaceID may be an empty string (i.e. "") if
// you wish to load the default space
octopusClient, err := client.NewClient(nil, apiURL, apiKey, spaceID)
if err != nil {
    _ = fmt.Errorf("error creating API client: %v", err)
    return
}

Once the client has been initialized, APIs can be targeted through the model and services available:

usernamePasswordAccount := accounts.NewUsernamePasswordAccount(name)
usernamePasswordAccount.Username = username

createdAccount, err := accounts.Add(octopusClient, usernamePasswordAccount)
if err != nil {
    _ = fmt.Errorf("error adding account: %v", err)
}

Operations like Add, DeleteByID, GetByID, and Update are supported by most services that are exposed through the client if not exposed in the package. These operations are configured at runtime since the Octopus REST API is hypermedia-driven.

Numerous code samples that showcase the API and this client are available in the examples directory. There are also many integration and unit tests available to examine that demonstrate the capabilities of this API client.

Testing

Running Tests Locally using Visual Studio Code

[!CAUTION] The integration tests will create and delete resources on your instance. Use a dedicated instance to run tests

To run the tests against an instance of Octopus Deploy, create a .env file at the root directory of this repository

OCTOPUS_HOST=http://your-octopus-instance-url
OCTOPUS_API_KEY=API-YOURAPIKEY

and add a Visual Studio Code workspace setting (.vscode/settings.json) for the test environment settings

{
    "go.testEnvFile": "${workspaceFolder}/.env"
}

🤝 Contributions

Contributions are welcome! ❤ Please read our Contributing Guide for information about how to get involved in this project.

Directories

Path Synopsis
examples
pkg
e2e
Package uritemplates is a level 4 implementation of RFC 6570 (URI Template, http://tools.ietf.org/html/rfc6570).
Package uritemplates is a level 4 implementation of RFC 6570 (URI Template, http://tools.ietf.org/html/rfc6570).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL