Learn Jenkins continuous integration (1) Jenkins installation, Gitlab installation, Gogs installation

One, Jenkins introduction

It is an open source software tool for continuous integration. Official website: http://jenkins-ci.org/.
Insert picture description here

Jenkins can implement monitoring integration errors, provide detailed log files and reminder functions, and visually display the trend and stability of project construction in the form of charts.
Features
 Easy to install: only one java -jar jenkins.war, After downloading the file from the official website, run it directly, without additional installation, and no database installation;
 Easy configuration: Provide a friendly GUI configuration interface;
 Change support: Jenkins can obtain and generate code from the code repository (Subversion/CVS) Update the list and output it to the compilation output information;
 Permalink support: users access Jenkins through the web, and the link addresses of these web pages are all
 JUnit/TestNG test report: that is, to provide detailed charts and other forms Test report function;
 Supports distributed build: Jenkins can distribute the integration build and other tasks to multiple computers to complete;
 File fingerprint information: Jenkins saves which jars files generated by which integrated build, and which integrated build used which Build records such as version jars files;
 Support third-party plug-ins: make Jenkins more and more powerful

Two, install Jenkins

1. Install the JDK environment

Jenkins needs to rely on the JDK environment

2. Download Jenkins

yum -y install wget   这样才能使用wget命令

wget https://pkg.jenkins.io/redhat/jenkins-2.83-1.1.noarch.rpm

Insert picture description here

3. Install Jenkins

rpm -ivh jenkins-2.83-1.1.noarch.rpm

Insert picture description here

4. Modify the configuration file

vi /etc/sysconfig/jenkins
设置为如下
JENKINS_USER="root"
JENKINS_PORT="8888"

Insert picture description here

5. Start the service, access

systemctl start jenkins

Startup failed:
Insert picture description here

systemctl status jenkins.service 

Insert picture description here

 vim /etc/init.d/jenkins

Insert picture description here
Reboot

systemctl daemon-reload
systemctl start jenkins

Insert picture description here

6. Browser access

http://localhost:8888/

I deployed it on the Alibaba Cloud server, so I use the public network ip to access. If you are deploying on the local machine, use it localhost. If it is a virtual machine, use the virtual machine ip address to
Insert picture description here
view the password:cat /var/lib/jenkins/secrets/initialAdminPassword
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

7. Install the plugin

If the plug-in download fails, click on the automatic upgrade, and then the address bar localhost:8888/restart to restart
click - "System management - "Manage plug-ins - "Optional plug-ins

Modify the Jenkins plug-in download address
Jenkins foreign official plug-in address download speed is very slow, so you can modify it to the domestic plug-in address: Jenkins->Manage Jenkins->Manage Plugins, click Available

cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

Insert picture description here

Finally, click on Manage Plugins and change the Update Site to the domestic plug-in download address https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

After Sumbit, enter: http://192.168.66.101:8888/restart in the browser to restart Jenkins.

Download Chinese Sinicization plugin

Insert picture description here

Install git plugin

Insert picture description here

Insert picture description here

Download the Role-based Authorization Strategy plugin

We can use the Role-based Authorization Strategy plug-in to manage Jenkins user permissions.
Insert picture description here
Insert picture description here
Switch the authorization strategy to "Role-Based Strategy" and save
Insert picture description here

Creating a Role:

Insert picture description here
Insert picture description here

Click "Manage Roles"
Insert picture description here
Global roles: Administrators and other advanced users can create global-based roles. Project roles: Roles for a certain project or certain projects Slave roles: Node-related permissions

We add the following three roles:

  1. baseRole: The role is a global role. This role needs to be bound to the Read permission under Overall in order to bind the most basic Jenkins access permissions to all users. Note: If you do not bind this role to subsequent users, an error will be reported: Username is missing the Overall/Read permission
  2. role1: This role is a project role. Use regular expression to bind "wx.*", which means that only items starting with wx can be operated.
  3. role2: This role is also a project role. Binding "monitor.*" means that only the items at the beginning of monitor can be operated.

Add user

Enter Manage Users on the system management page
Insert picture description here

Insert picture description here
Insert picture description here

Assign roles to users

Enter Manage and Assign Roles on the system management page, and click Assign Roles. The
binding rules are as follows:
eric users are bound to baseRole and role1,
jack users are bound to baseRole and role2 respectively

Create project test permissions

Create two projects with an administrator account, namely wx01 and monitor01. The
result is:
eric user login, can only see wx01 project
jack user login, can only see monitor01 project

Install the Credentials Binding plugin

Credentials can be used to store database passwords that require ciphertext protection, Gitlab password information, Docker private warehouse passwords, etc., so that Jenkins can interact with these third-party applications.
Install the Credentials Binding plug-in To use the credential management function in Jenkins, you need to install the Credentials Binding plug-in.
Insert picture description here
Click: Manage Credentials --"Global--"Add credentials

Insert picture description here
Insert picture description here
Insert picture description here

After installing the plug-in, there is a "Credentials" menu on the left, where
you can manage all credentials . There are 5 types of credentials that can be added:

  1. Username with password: username and password
  2. SSH Username with private key: Use SSH user and key
  3. Secret file: A text file that needs to be kept secret. When used, Jenkins will copy the file to a temporary directory, and then set the file path to a variable. After the build is completed, the copied Secret file will be deleted.
  4. Secret text: An encrypted text string that needs to be saved, such as DingTalk or Github api token
  5. Certificate: By uploading certificate files
    Commonly used credential types are: Username with password (user password) and SSH Username with private key (SSH key)
    Insert picture description here

8. Global tool configuration

Insert picture description here

Configure the JDK directory

Insert picture description here

Configure Maven

Insert picture description here

Global tool configuration is associated with JDK and Maven
Manage Jenkins->Configure System->Global Properties, add three global variables
Insert picture description here

Three, install Gitlab

GitLab is an open source project for warehouse management system. It uses Git as a code management tool and builds a
web service on this basis .
Gitlab installation

  1. Installation related dependencies
yum -y install policycoreutils openssh-server openssh-clients postfix
  1. Start ssh service & set to boot
systemctl enable sshd && sudo systemctl start sshd
  1. Set postfix to start and start automatically after booting. Postfix supports gitlab sending function systemctl enable postfix && systemctl start postfix
  2. Open ssh and http services, and then reload the firewall list
firewall-cmd --add-service=ssh --permanent 
firewall-cmd --add-service=http --permanent 
firewall-cmd --reload

If you turn off the firewall, you do not need to do the above configuration.
5. Download the gitlab package and install it
. Download the installation package online:

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm

installation:

rpm -i gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm
  1. Modify gitlab configuration
vi /etc/gitlab/gitlab.rb

Modify the gitlab access address and port, the default is 80, we change it to 82

external_url 'http://192.168.66.100:82'nginx['listen_port'] = 82
  1. Overload configuration and startup
gitlab gitlab-ctl reconfigure
gitlab-ctl restart
  1. Add port to firewall
firewall-cmd --zone=public --add-port=82/tcp --permanent
firewall-cmd --reload

After the startup is successful, you will see the following page to modify the administrator root password. After modifying the password, log in

Fourth, install Gogo

Gogs is a self-service Git service that is extremely easy to build.
Gogs' goal is to create the easiest, fastest and easiest way to build self-service Git services. Use Go language development

It’s the same as Git, you can use gogs to build a private git server, and the same is Gitlab Gitlub Gitea...

Install Docker first

yum install -y docker
# 开启DOCKER服务
systemctl start docker.service
# 查看安装结果
docker version
# 设置开机启动
systemctl enable docker.service
# 配置DOCKER镜像下载加速
vim /etc/docker/daemon.json
# 在其中加入加速镜像源地址即可:
{
    
    
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
# 重启 docker 服务即可
systemctl daemon-reload 
systemctl restart docker.service

Pull gogs mirror

docker pull gogs/gogs

Insert picture description here

Create a container

docker run -d --name=gogs -p 10022:22 -p 3000:3000 -v /var/gogsdata:/data gogs/gogs

Insert picture description here

You will enter the first run of the installer page, we
can choose a database as the storage of gogs data, the simplest is to choose SQLite3. For larger companies, you can choose MySQL.
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here

Insert picture description here

Create warehouse

Insert picture description here

Guess you like

Origin blog.csdn.net/DreamsArchitects/article/details/109305508