Automatic integration of gitlab-ci
This document is installed with the rpm package. For source code installation, please refer to the documentation:
Https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
Environment:
Gitlab server: 10.0.10.50 centos7.3
Gitlab-runner server: 10.0.10.30 centos7.3
One: installation and use of gitlab:
1: go to the gitlab website to download the corresponding version: https://about.gitlab.com/installation/rpm-ivh gitlab-ce-9.2.5-ce.0.el7.x86_64.rpm 2: modify the host in the configuration file of gitlab The default is the host name of the machine [root@gitlab-ci system] # vim / var/opt/gitlab/gitlab-rails/etc/gitlab.yml startup mode 1: [root@gitlab-ci system] # systemctl start gitlab-runsvdir startup mode 2: [root@gitlab-ci opt] # gitlab-ctl start Note: firewall and selinux pay attention to opening
3: enter the address in the browser:
Http://10.0.10.50 prompts you to change the password. The user name is root. Create a project test2 after entering.
2: installation and use of gitlab-runner 1: install For Debian/Ubuntucurl-L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bashFor RHEL/CentOScurl-L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bashFor Debian/Ubuntusudo apt-get install gitlab-runnerFor RHEL/CentOSsudo yum install gitlab-runner reference document: https://docs.gitlab .com/runner/install/linux-repository.html#installing-the-runner runs gitlab-runner Reference documentation: https://docs.gitlab.com/runner/register/index.html runs the following command: sudo gitlab-runner register enter your GitLab instance URL: Please enter the gitlab-ci coordinator URL (e.g. Https://gitlab.com) https://10.0.10.50 enter the token you obtained to register Runner: Please enter the gitlab-ci token for this runner 6Rz9bnmtcC8f4jQHwo8q enter the description of the Runner You can change it later in GitLab's UI: Please enter the gitlab-ci description for this runner [hostame] my-runner enter the tag associated with Runner, and you can change it later in GitLab's UI: Please enter the gitlab-ci tags for this runner (comma separated): my-tag,another-tag choose whether Runner should receive jobs without tags. You can make changes later in GitLab's UI (default is false): Whether to run untagged jobs [true/false]: [false]: true chooses whether to lock Runner to the current project, and you can make changes later in GitLab's UI. Useful when Runner is specific (default is false): Whether to lock Runner to current project [true/false]: [false]: false enter Runner executor: Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:docker2: launch gitlab-runner [root@os7 ~] # gitlab-runner start after registration is successful
3: check the status of gitlab-runner under the gitlab server
Visit url: http://10.0.10.50/admin/runners
Three: use gitlab-runner
1: create a file under the test2i project of gitlab. Gitlab-ci.yml
For the syntax of .gitlab-ci.yml files, please refer to the following documents:
Http://10.0.10.50/help/ci/yaml/README.md
Sample template documents supported by gitlab-ci. Such as PHP,JAVA,IOS, etc.
Http://10.0.10.50/help/ci/examples/README.md
Contents of the .gitlab-ci.yml file:
Note:
The script for 1:script to execute commands is run as gitlab-runner user, and should be run through sudo, otherwise automating the deployment of the project with shell script will report a permission error.
2: the executed script file should be placed on the gitlab-runner server
After the Commit is submitted to the server, clicking pipelines will show that the build failed because the test2 project is not connected to the gitlab-runner
2: add project test2 to gitla-runner: activate the test2 project
3: modify the files under the test2 project, and commit to see the results.
There will be a green sign indicating that the execution was successful, and look at the output:
This tutorial simply describes the use of gitlab-ci automatic integration, can customize the automatic deployment of your project in gitlab, and perfectly replaces jenkins