GoCD - Continuous Delivery Pipelines

GoCD is an open source continuous integration and continuous delivery system. Compared with Jenkins, GoCD focuses on composing workflows, turning the build-test-release lifecycle into a pipeline, fully embodying the arguments made in the book “Continuous Delivery: Reliable Software Releases through Build, Test, and Deployment Automation”.

Installation

GoCD consists of GoCD Server and GoCD Agents; a build requires at least one GoCD Agent.

GoCD Server provides a UI for users to control the entire GoCD system, and distributes work to agents.

GoCD Agents carry out the work handed down by the server (running commands, deploying projects, etc.)

https://www.gocd.org/assets/images/go.cd_server-and-agents-8a7f4cd3.svg

GoCD Server

System requirements:

  • RAM - minimum 1GB, 2GB recommended

  • CPU - minimum 2 cores, 2GHz

  • Disk - minimum 1GB free space

  • env - Java Runtime Environment (JRE) version 8

echo "deb https://download.gocd.org/" | sudo tee /etc/apt/sources.list.d/gocd.list
curl https://download.gocd.org/GOCD-GPG-KEY.asc| sudo apt-key add -
sudo apt update
sudo apt install apt-transport-https openjdk-8-jre
sudo apt install go-server

After installation, the following files are created:

/var/lib/go-server #包含二进制文件和数据
/etc/go #包含 pipeline 配置
/var/log/go-server #包含 server 日志
/usr/share/go-server #包含启动脚本
/etc/default/go-server #包含默认的环境变量

Start it: sudo systemctl start go-server

GoCD Agents

System requirements:

  • RAM - minimum 128MB, 256MB recommended

  • CPU - minimum 2GHz

  • env - Java Runtime Environment (JRE) version 8

System dependencies were already handled during GoCD Server installation, so here you just need to install GoCD Agents sudo apt install go-agent. After installation, the following files are created:

/var/lib/go-agent #包含二进制文件
/usr/share/go-agent #包含启动脚本
/var/log/go-agent #包含 agent 日志
/etc/default/go-agent #包含默认的环境变量

Configuration:

If GoCD Agents and the GoCD server aren’t on the same machine, you need to configure the GoCD server’s IP address

  1. Edit /etc/default/go-agent

  2. Change the line GO_SERVER_URL=https://127.0.0.1:8154/go, replacing 127.0.0.1 with the GoCD server’s IP address

Start it: sudo systemctl start go-agnet

Usage

Before creating a new pipeline, let’s first go over some basic concepts

https://www.gocd.org/assets/images/go.cd_stage-jobs-tasks-a58d5b3b.svg
  • Task: the smallest unit within a Pipeline, used to run a single linux command

  • Job: a collection of tasks that run in a specified order. If one task fails, the job also fails, and the remaining tasks no longer run.

  • Stage: a collection of jobs with no ordering dependency between them, so jobs within one Stage can run at the same time. If one job fails, the stage also fails, but the other jobs still finish running.

  • Pipeline: a collection of stages that run in a specified order. If one stage fails, the pipeline also fails, and the remaining stages no longer run.

https://www.gocd.org/assets/images/go.cd_pipelines-materials-e64b8575.svg
  • Material: a material can trigger a pipeline run; a material is usually a source code repository. The GoCD Server continuously polls the material, and when a change is detected, the pipeline starts running

Creating a Pipeline

  1. On the Add pipeline page, we use the project name as the pipeline name, and use the group from the git repository as the pipeline group

  2. Configure Materials, filling in the git repository address and branch

  3. Configure the Stage/Job; here the stage is named CI, indicating it’s the continuous integration stage

  4. Specify the task action; here we run a docker container that includes its own tests

Running the Pipeline

After every git repository commit, the Pipeline run is triggered, and GoCD Server records the build results of each stage