← Back to DevBytes

GoCD: Complete Configuration Guide

Introduction to GoCD

GoCD is an open-source continuous delivery server designed to model complex software delivery workflows. Unlike simpler CI tools, GoCD emphasizes end-to-end visibility through its value stream map, and supports advanced pipeline modeling with fan-in, fan-out, and dependency management. A complete understanding of its configuration is essential to harness these capabilities.

Why it matters: Modern delivery pipelines involve multiple teams, services, and environments. GoCD's configuration lets you define exactly how changes flow from code commit to production, enabling traceability, reproducibility, and controlled promotion. Mastering its configuration unlocks true continuous delivery.

Core Configuration Concepts

🚀 Deploy your AI agent in 10 minutes

Managed Hermes hosting. Zero DevOps. 100M tokens/mo included.

Try it free →

GoCD configuration is stored in a central XML file (or multiple JSON files in newer versions) that defines pipelines, stages, jobs, tasks, agents, environments, and more. The main concepts are:

Configuring Your First Pipeline

Let’s create a simple pipeline with one stage and one job that checks out code and runs a build script. In traditional XML configuration, you would define this in cruise-config.xml:

<?xml version="1.0" encoding="utf-8"?>
<cruise xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="cruise-config.xsd">
  <server>
    <security>
      <!-- Authentication and authorization -->
    </security>
  </server>
  <pipelines>
    <pipeline name="my-app-build">
      <materials>
        <git url="https://github.com/example/my-app.git"
             branch="main"
             materialName="my-app-repo" />
      </materials>
      <stage name="build" cleanWorkingDir="false">
        <job name="compile">
          <tasks>
            <exec command="make">
              <arg>clean</arg>
              <arg>all</arg>
              <runIf status="passed" />
            </exec>
          </tasks>
          <artifacts>
            <artifact src="target/*.jar" dest="dist" />
          </artifacts>
        </job>
      </stage>
    </pipeline>
  </pipelines>
  <environments>
    <environment name="development">
      <agents>
        <physical uuid="agent-1-uuid" />
      </agents>
    </environment>
  </environments>
</cruise>

This example defines a pipeline triggered by changes to the main branch. The single stage "build" contains a job "compile" that executes make clean all and collects JAR artifacts. The pipeline uses an agent assigned to the "development" environment.

In newer GoCD versions, you can also define pipelines using JSON configuration plugins or the GoCD API. For instance, a JSON equivalent might look like:

{
  "name": "my-app-build",
  "materials": [
    {
      "type": "git",
      "url": "https://github.com/example/my-app.git",
      "branch": "main",
      "name": "my-app-repo"
    }
  ],
  "stages": [
    {
      "name": "build",
      "cleanWorkingDir": false,
      "jobs": [
        {
          "name": "compile",
          "tasks": [
            {
              "type": "exec",
              "command": "make",
              "arguments": ["clean", "all"],
              "runIf": ["passed"]
            }
          ],
          "artifacts": [
            {
              "source": "target/*.jar",
              "destination": "dist"
            }
          ]
        }
      ]
    }
  ]
}

This JSON can be used with the GoCD configuration repository or the API to create pipelines programmatically.

Advanced Pipeline Modeling

GoCD shines when modeling complex workflows. You can connect pipelines as materials, enabling fan-in (multiple upstream pipelines trigger a downstream one) and fan-out (one pipeline triggers multiple downstream pipelines). This creates a value stream map that visualizes the entire delivery flow.

Example: A deployment pipeline that depends on two independent build pipelines:

<pipeline name="deploy-to-staging">
  <materials>
    <pipeline pipelineName="service-a-build" stageName="build" />
    <pipeline pipelineName="service-b-build" stageName="build" />
  </materials>
  <stage name="deploy">
    <job name="deploy-scripts">
      <tasks>
        <fetchPipeline pipelineName="service-a-build"
                       stageName="build"
                       jobName="compile"
                       src="dist"
                       dest="artifacts/service-a" />
        <fetchPipeline pipelineName="service-b-build"
                       stageName="build"
                       jobName="compile"
                       src="dist"
                       dest="artifacts/service-b" />
        <exec command="deploy.sh" />
      </tasks>
    </job>
  </stage>
</pipeline>

Here, the deploy pipeline automatically triggers when both service builds complete successfully. It fetches artifacts from each upstream pipeline and then executes deployment. This pattern ensures consistent, coordinated releases.

Managing Environments and Agents

Environments group pipelines and agents to separate concerns, like development, staging, and production. Agents are registered by their UUID and can be assigned to environments. You can also set environment variables scoped to an environment.

Example environment definition:

<environment name="production">
  <agents>
    <physical uuid="prod-agent-1" />
    <physical uuid="prod-agent-2" />
  </agents>
  <pipelines>
    <pipeline name="deploy-to-prod" />
  </pipelines>
  <environmentvariables>
    <variable name="TARGET_CLOUD">
      <value>aws</value>
    </variable>
  </environmentvariables>
</environment>

This restricts the production pipeline to only run on specified agents, and injects the TARGET_CLOUD variable into all jobs in that environment.

Using Configuration Repositories

GoCD supports configuration as code through config repositories. Instead of a monolithic XML file, you can store pipeline definitions in a Git repository, enabling team ownership, pull request reviews, and versioned configuration history. The server polls these repos and merges definitions.

To set up a config repo, define it in the server configuration:

<config-repos>
  <config-repo id="team-alpha-pipelines">
    <git url="https://github.com/my-org/gocd-pipelines.git" />
  </config-repo>
</config-repos>

Inside that Git repo, you place JSON or YAML pipeline files (depending on plugin). For example, a file pipelines/frontend.yaml (with appropriate plugin) can define a pipeline. This approach scales configuration across large organizations.

Best Practices for GoCD Configuration

Conclusion

GoCD’s configuration model provides the flexibility needed for modern continuous delivery. By understanding pipelines, stages, jobs, materials, and environments, you can craft workflows that accurately reflect your team’s delivery process. Adopting best practices like configuration as code, modular templates, and secure secret management ensures your pipelines are maintainable, scalable, and reliable. With the examples and concepts in this guide, you have a complete foundation to configure GoCD for any delivery scenario.

🚀 Need a reliable AI agent for your project?

Deploy Hermes Agent in 10 minutes. Managed hosting, zero DevOps.

Get Started — $23.99/mo
← Back to all articles