Skip to main content

Install Go agent in a pipeline

Using the Agent Wizard is the simplest way to deploy a new agent by selecting Language-specific > Go > Install in a pipeline.

Select the installation method

Select GitHub or Bitbucket.

Configure the agent

Configure the Go agent.

A connection token is the recommended method. Set CONTRAST__API__TOKEN in the environment where you run your application.

Install the agent in GitHub

The Go agent is installed by replacing go with contrast-go in the command that builds your application. The contrast-go build command builds an executable with Contrast embedded in it. Command line arguments for Go are also available.

  1. If you use GitHub pipelines, add the following step to your GitHub Action to install contrast-go:

    - name: Install contrast-go
      shell: bash
      run: |
        go run github.com/contrast-security-oss/contrast-go-installer@latest latest
  2. Replace go build with contrast-go build in your build step with the following code:

    - name: Build instrumented app
      run: contrast-go build -o output-name-of-application
  3. Add the following environment variables to the step running your application:

    env:
      CONTRAST__API__TOKEN: ${{ secrets.ContrastAPIToken }}
      CONTRAST__APPLICATION__NAME: ${{ secrets.ContrastApplicationName }}
      CONTRAST__APPLICATION__METADATA: ${{ secrets.ContrastApplicationMetadata }}

Install the agent in Bitbucket

  1. If you use Bitbucket Pipelines, add the following step to your pipeline to install the agent:

    - step:
        script:
            - go run github.com/contrast-security-oss/contrast-go-installer@latest latest
  2. Build the application by replacing your normal go build command with contrast-go build. This builds an executable with Contrast embedded in it:

    contrast-go build -o output-name-of-application
  3. Store the API token in a Bitbucket secured variable named CONTRAST__API__TOKEN so the agent can read it from the environment when the application runs.

Verify the agent deployment

Interact with your application as you normally would. For example, interact with your application's web interface or send API commands.

  1. In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.

  2. Verify that you see the name of your application in the applications list.

    • In Northstar, select Applications from the left navigation.

    • In Contrast, select Applications from the header.

  3. Verify that you see the name of your local server in the servers list.

    • In Northstar, select Servers from the left navigation.

    • In Contrast, select Servers from the header.