文件目录结构
.
├── docker-compose.yml
├── gitlab
│ ├── config
│ ├── data
│ └── logs
└── jenkins
├── apache-maven-3.6.2-bin.tar.gz
└── jenkins_home
使用docker-compose启动jenkins和gitlab的容器,模拟CI过程。
公钥
jenkins(web页面) ---------- > gitlab
^
|
|私钥
|
jenkins容器
docker-compose:
version: '3.2'
services:
gitlab:
image: gitlabcicd:latest
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://10.0.122.148:80'
unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 3 # worker进程数
unicorn['worker_memory_limit_min'] = "200 * 1 << 20" # worker最小内存
unicorn['worker_memory_limit_max'] = "300 * 1 << 20" # worker最大内存
sidekiq['concurrency'] = 10
postgresql['shared_buffers'] = "128MB"
postgresql['max_worker_processes'] = 8
networks:
- jumpserver-test
ports:
- '9280:80'
volumes:
- './gitlab/config:/etc/gitlab'
- './gitlab/logs:/var/log/gitlab'
- './gitlab/data:/var/opt/gitlab'
jenkins:
image: jenkinscicd:latest
restart: always
privileged: true
user: root
volumes:
- type: bind
source: ./jenkins/jenkins_home
target: /var/jenkins_home
- type: bind
source: /Volumes/data/com.docker.docker/Data/docker.sock
target: /var/run/docker.sock
read_only: "yes"
networks:
- jumpserver-test
ports:
- "9980:8080"
volumes:
mysqldb:
networks:
jumpserver-test:
gitlab的环境变量用于优化gitlab在本地的服务
jenkins配置
关于邮件的设置
CI
jenkins
1.新建任务:
创建一个任务,选择任务的项目可类型
freestyle或者maven或者pipline最为常见
2.描述:
项目描述
3.源码管理:
选择git,url即为仓库的地址(由于使用的容器,这里的ip需写为容器的ip),
凭据可以使用用户的帐号(username or password),私钥的方式(SSH username with private key)
指定分支
4.构建触发器
Build when a change is pushed to GitLab. GitLab webhook URL: http://xx:x/project/auto_cmdb
5.针对不同的项目选择不同的构建方法和构建后操作
gitlab
选择具体的仓库的settings的inetgrations
url即为构建触发器的url,当然,url里的ip同样需要更改,端口为内部使用端口(容器与容器之间通信)
在下方的push events的选项中填写webhook需要监控的分支
这样,当该分支进行push操作时就会触发构建,执行jenkins里设定的构建操作及构建后的操作
实现CI
网友评论