Build a gocd environment

Original link:

As an integrated CICD tool, gocd occupies a large part in the Fortune Global 500. My company is Thoughtworks, which is the company that develops and maintains gocd. I also use gocd in my daily work. The introduction of gocd is relatively small, and it happens that I am learning about gocd recently, so I will summarize the use of gocd and share it.

I personally think that the most important thing for a software is to use it, then install it, and then understand its principle, debug, or understand its principle through debug, and then look at its code. You can’t just focus on learning how to install and understand its code, and forget that the ultimate purpose of software is to simplify the complicated work.

Although the process mentioned above is to learn how to use it first and then learn to install it, the reality does not seem to be as ideal as imagined. In real life, there is no environment that we can test at will, for us to try and make mistakes. Therefore, the problem comes down to the installation and construction environment. This is a difficult place to circumvent. I hope there will be a solution to circumvent it in the future. Of course, some managed services we see now have done this, such as managed Kubernetes managed mysql, etc., which can avoid any situation that we are not familiar with. The blow that comes with manual installation.

Let’s go back to the main topic, we mainly use Linode this time (I also tried the vultr manufacturer, but I couldn’t ssh to the machine after opening three machines, so I gave up, it is estimated that the problem is caused by too many vultr used for scientific Internet access) Cloud service vendors build our gocd environment, because it can be turned on and off at any time, without incurring additional costs. Other cloud service vendors such as Linode and digitalOcean are all cloud service vendors that are friendly to developers. Company, if you do not have a relevant account for the time being, you can register through our connection, and you can also get relevant discounts. At the same time, it is also equivalent to sponsoring me through the manufacturer to reduce the actual cost of my cloud service. If you have not registered, you can Register through my link, vultr $10 registration discount address , vultr $100 discount registration address, but $100 is valid for 14 days , linode $100 is valid for 60 days . But here is a mention, if you don’t reach the corresponding expenses, you will not reward me with the free amount of cloud services, but I still hope that everyone can effectively use the benefits given by cloud service manufacturers to learn and improve their abilities.

One thing that needs to be clear about gocd is that its architecture is a master-slave architecture (which is similar to kubernetes). The master node is mainly used to manage the system, assign tasks and provide user interfaces .

The strategy we adopted this time is to demonstrate the mode of one master node and two slaves. The main purpose of this article is to use the CentOS system to install and run gocd and connect to the node node.

The gocd official website also has these specific tutorials. We will describe the installation steps through examples, which are mainly divided into three parts: 1. Install go-server 2. Install go-agent 3. Connect go-server and go-agent

1. Install go-server

First, we ssh to the machine for specific content, please refer to

 # 添加yum源sudo curl -o /etc/yum.repos.d/gocd.repo# 安装go-serversudo yum install -y go-server

Installation success message


After the installation of our gocd server is completed through the above steps, let’s start the gocd-server

gocd-server mainly starts the script through service as follows

Script Description
service go-server console Start the GoCD server in the foreground
service go-server start Start the GoCD server as a daemon in the background
service go-server stop Stop the GoCD server
service go-server restart restart gocd server

So for us now, we can start it directly with service go-server start

 # 启动gocd-server 服务service go-server start# 检测服务状态service go-server status

The service is successfully started as shown in the following figure


At this point we can access our gocd-server through http://:8153/go

There is one place to pay attention to because CentOS7 on Linode has iptables enabled by default for port protection. During our testing phase, we can temporarily disable iptables. The specific commands are as follows

 # 关闭iptablessystemctl stop firewalld# 查看iptables 状态systemctl status firewalld

Close the screenshot below:


The screenshot of my gocd-server success is as follows


At this point we have successfully completed the installation of the gocd-server side

2. Install the go-agent client and connect

Next we start to prepare the go-agent client

The installation process is similar to gocd-server

 # 添加yum源sudo curl -o /etc/yum.repos.d/gocd.repo# 安装gocd-agent 服务sudo yum install -y go-agent

The startup command is as follows (but before startup, you need to modify the configuration of gocd to bind it to gocd-server)

Script Description
service go-agent console Start the GoCD agent in the foreground
service go-agent start Start the GoCD agent as a daemon in the background
service go-agent stop Stop the GoCD agent
service go-agent restart Restart the GoCD agent

service utilizes the service manager (eg systemd, upstart, init.d) used by your OS.

Configure gocd-agent to bind gocd-server

Before configuring we first turn off the firewall

 # 关闭iptablessystemctl stop firewalld# 查看iptables 状态systemctl status firewalld
  • Open /usr/share/go-agent/wrapper-config/wrapper-properties.conf with your IDE
  • Configure the address of the Gocd server according to the instructions in this file
  • save and exit your compiler
  • Run service go-agent [start|restart] to (restart) start your go-agent service

Examples are as follows


Modified content


So we can start the service of go-agent

 # 启动go-agent 服务service go-agent start# 查看go-agent 状态service go-agent status

The effect of startup completion is as follows:


Let’s go to gocd-server to check whether the registration is successful. At this time, enter the address of gocd-server to view

We click on the top label agent and we find that the agent just now is already in the pending state and the effect is as follows


Why is it the pending state instead of the directly used state? Because through the above process, we can see that we do not have any protective mechanism to ensure that other people’s agents cannot be registered on our server. If our code is directly in the It is difficult to talk about security when running on other people’s machines, so we need to manually start this service. How to start it manually?

Select this agent and click enable, the effect is as follows


After startup, the state of the agent is converted from pending to Idle state, the effect is as follows


If we want to configure multiple agents, repeat the above code

The renderings of multiple agents are as follows


At this point, our service of installing go-agent and connecting with the server is completed

Next, I will record the video of this part and upload it to the Internet and add it to this part

In fact, we have only completed the construction of the gocd environment here, and have not tested it yet. In the subsequent articles, the corresponding running content will be added.

Later: Linux-based service management (such as service and systemctl)

Reference article

  3. []

Building a gocd environment first appeared on Li Hui Blog .

This article is transferred from:
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.