gitlab+jenkins+webhook 代码发布
Posted HoneyBuddy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab+jenkins+webhook 代码发布相关的知识,希望对你有一定的参考价值。
https://docs.gitlab.com/omnibus/docker/ 官方参考文档
root@iZm5e68cj7e7kx71atc98eZ:~# sudo docker pull gitlab/gitlab-ce:latest
latest: Pulling from gitlab/gitlab-ce
18d680d61657: Pull complete
0addb6fece63: Pull complete
78e58219b215: Pull complete
eb6959a66df2: Pull complete
8f56c4bb1d27: Pull complete
6145e9d33b6a: Pull complete
70f6a2fb2280: Pull complete
e6c8215808aa: Pull complete
df7e9faf62df: Pull complete
87f06c1e794b: Pull complete
root@iZm5e68cj7e7kx71atc98eZ:/var/gitlab# mkdir config
root@iZm5e68cj7e7kx71atc98eZ:/var/gitlab# mkdir logs
root@iZm5e68cj7e7kx71atc98eZ:/var/gitlab# mkdir data
root@iZm5e68cj7e7kx71atc98eZ:/var/gitlab# sudo docker run --detach \\
> --hostname gitlab \\ 可以设置成Ip 和下载地址有关
> --publish 8443:443 --publish 8888:80 --publish 2222:22 \\
> --name gitlab \\
> --restart always \\
> --volume /var/gitlab/config:/etc/gitlab \\
> --volume /var/gitlab/logs:/var/log/gitlab \\
> --volume /var/gitlab/data:/var/opt/gitlab \\
> gitlab/gitlab-ce:latest
cb04f1726e3a6a1cd94a7d63438cff6c13c16900a47a566d7fc4a099f4abfd46
添加组成员
创建用户
邮件设置
root@gitlab:/#cat /etc/gitlab/gitlab.rb
gitlab_rails[\'smtp_enable\'] = true
gitlab_rails[\'smtp_address\'] = "smtp.sina.com"
gitlab_rails[\'smtp_port\'] = 587
gitlab_rails[\'smtp_user_name\'] = "houpj@sina.com"
gitlab_rails[\'smtp_password\'] = "123456"
gitlab_rails[\'smtp_domain\'] = "sina.com"
gitlab_rails[\'smtp_authentication\'] = "login"
gitlab_rails[\'smtp_enable_starttls_auto\'] = true
gitlab_rails[\'smtp_tls\'] = false
gitlab_rails[\'gitlab_email_from\'] = \'houpj@sina.com\'
修改权限
组内添加项目
设置ssh密钥用来git clone 项目
root@iZm5e68cj7e7kx71atc98eZ:~/.ssh# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:62VhUNby9iIC7q66f3VxzY6l4XgRay7A1SPlocdQomo root@iZm5e68cj7e7kx71atc98eZ
The key\'s randomart image is:
+---[RSA 2048]----+
| ==+ |
| ++*=. |
| .o..++* |
| ..o...O + |
| .E.S.oO O |
| .. oo=.B o |
| . ..oo+ . |
| o. o |
| o+o+. . |
+----[SHA256]-----+
root@iZm5e68cj7e7kx71atc98eZ:~/.ssh# ls
authorized_keys id_rsa id_rsa.pub known_hosts
root@iZm5e68cj7e7kx71atc98eZ:~/.ssh# chattr -i authorized_keys
root@iZm5e68cj7e7kx71atc98eZ:~/.ssh# cat id_rsa.pub >> authorized_keys
复制公钥到gitlab
root@iZm5e68cj7e7kx71atc98eZ:~/.ssh# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpFtcntTkCM5KjIe3ChsUJ7M2wvExQasKokFxnc/bPcNrYMJ+UtTQFA3wiHdPN892BCqzv1rHEC4oUcW4W7SVzZouzS1dxfMQzM+Z0CB0YBVn2g8QWVJxJXuW7bCWEB8OICew/UyitftZbzevGUMXwJUXLtIZOlhtloHkeEWTonUu5xU1uwZ59gIT3HPaL/0Mo0uVZtP1MP1jG6G5qvLGXX/3PPScnKDJQ7cmbsLKnEpJ0PQJkpE4woqWWIALDmHzPbOF1ubB6Auo4vRCNWO+dNwSU7dwZjfwAqhTFvSUZ/G9dW4PvN6153nGgvKY2N41gktiizJRPXpPMy/WtpMTz root@iZm5e68cj7e7kx71atc98eZ
默认的url不能使用
修改克隆url
root@gitlab:/# cat /etc/gitlab/gitlab.rb
### GitLab Shell settings for GitLab
gitlab_rails[\'gitlab_shell_ssh_port\'] = 2222
# gitlab_rails[\'gitlab_shell_git_timeout\'] = 800
ssh://git@gitlab:2222/devops/devops_test.git
gitlab换成公网ip
ssh://git@123.123.123.123:2222/devops/devops_test.git
root@iZm5e68cj7e7kx71atc98eZ:~# git clone ssh://git@123.123.123.123:2222/devops/devops_test.git
Cloning into \'devops_test\'...
The authenticity of host \'[123.123.123.123]:2222 ([123.123.123.123]:2222)\' can\'t be established.
ECDSA key fingerprint is SHA256:eQmb5j6h8fPc0efCAo/dlfCfnhLc9QRblNldRJPceaU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added \'[123.123.123.123]:2222\' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
jenkins安装插件
jenkins通过gitlab用户连接
Webhook设置
在gitlab里填写jenkins配置
测试配置
jenkins构建成功
以上是关于gitlab+jenkins+webhook 代码发布的主要内容,如果未能解决你的问题,请参考以下文章
jenkins系列3-gitlab webhook,jenkins自动构建
jenkins系列3-gitlab webhook,jenkins自动构建
jenkins 配置 gitlab webhook 实现自动发布