An overview of the
In traditional software development, the integration of code is usually done by everyone at the end of the project, which often takes a lot of time and effort. Continuous integration is the practice of putting the integration phase into the software development phase so that code can be built, tested, and integrated more regularly.
“Continuous integration doesn’t eliminate bugs, it makes them very easy to find and fix.”
Continuous integration allows developers to build and unit test new code as soon as they submit it. This allows us to use the test results to determine whether the new code or environment configuration integrates correctly with the original code or environment configuration of other developers.
GitLab CI is already integrated in GitLab, we just need to add a.gitlab-ci.yml file to the project, and then add a Runner to carry out continuous integration. And as GitLab upgrades, it becomes more and more powerful.
CI preparation
Docs.gitlab.com/runner/inst… CI operation requires the installation of GitLab Runner. The above links include a variety of installation methods. This article introduces the installation methods of Docker
docker pull gitlab/gitlab-runner:latest
docker run -d --name gitlab-runner --restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
gitlab/gitlab-runner:latest
Copy the code
Docker exec gitlab-runner -it bash install Java and Maven
Java and Maven are installed in the container
wget https://repo.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-x64.tar.gz wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz tar ZXVF. - Jdk-8u201-linux-x64.tar. gz mv jdk1.8.0_201 tar -xvf apache-3.6.3-bin.tar. gzCopy the code
Configuring environment Variables
vim /etc/profile
exportJAVA_HOME = / opt/jdk1.8.0 _201exportMAVEN_HOME = / opt/apache maven -- 3.6.3export PATH=${JAVA_HOME}/bin:${MAVEN_HOME}/bin:${PATH}
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Copy the code
Reload the system configuration file source /etc/profile
How does the project use CI
.gtilab-ci.yml file is stored in the root directory of the project in the warehouse, which is used to define Pipeline in GitLab CI/CD. In fact, it is nothing more than a configuration file, it is quite simple to understand, we mainly need to understand the concept of Pipeline and how to configure a.gitlab-ci.yml
Create a.gitlab-ci.yml file for the project with the following contents
build:
script: "pwd && mvn install"
Copy the code
If you run permission denied or cannot find the MVN command, the reason is that your maven installation is in the directory you created. The installation path is wrong. The script in gitlab-ci.yml is executed by a user named gitlab-runner who can only access things in the /home/gitlab-runner folder. If some commands are executed in other locations, /etc/gitlab-runner/config.toml /gitlab-runner/config.toml
vi /etc/gitlab-runner/config.toml
## Append content
[runners.docker]
tls_verify = false
image = "latest"
privileged = true
disable_cache = false
volumes = ["/cache"]
Copy the code
GitLab configures the Runner to run CI
gitlab-ci-multi-runner register
Copy the code
Enter the URL and token specified in 2 and 3 as prompted
You can see that the Settings are successful
Trigger CI through API
The effect
Develop reading
Maven configures multiple repositories
gitlab ci shell script permission denied
Triggering pipelines through the API
Install GitLab Runner
GitLab CI + Docker realizes continuous integration