Jenkins
- 一、docker安装Jenkins
- 1.linux
- 2.web
- 二、流水线
- 1.gitlab连接jenkins
- 1.jenkins服务器创建密钥
- 2.将密钥添加到gitlab上
- 3.创建gitlab访问令牌
- 4.安装jenkins插件
- 5.配置 GitLab 凭据
- 2.创建流水线
- 1.新增凭证配置 Username with password
- 2.创建任务
- 3.构建触发器
- 4.构建
- 5.配置gitlab
- 1.修复gitlab报错
- 2.测试 Webhook 配置
- 6.推送文件到gitlab(192.168.122.30)
Jenkins官网 https://www.jenkins.io/zh/doc/book/installing/
主机ip:192.168.122.30 端口:8080
一、docker安装Jenkins
1.linux
mkdir /var/jenkins_home
docker run -u root --rm -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
docker ps -a
netstat -tlnup|grep 8080
http://192.168.122.30:8080/
2.web
[root@master ~]# docker exec -it 0cc05426358c sh
/ # cat /var/jenkins_home/secrets/initialAdminPassword
二、流水线
1.gitlab连接jenkins
创建gitlab详见
https://blog.csdn.net/weixin_55609905/article/details/119979282
1.jenkins服务器创建密钥
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub
2.将密钥添加到gitlab上
3.创建gitlab访问令牌
4.安装jenkins插件
进入“插件管理”,安装插件:GitLab、Generic Webhook Trigger、Git Parameter、Publish Over SSH,安装完插件重启系统
5.配置 GitLab 凭据
2.创建流水线
1.新增凭证配置 Username with password
2.创建任务
3.构建触发器
选择
Build when a change is pushed to GitLab. GitLab webhook URL: http://192.168.122.30:8080/project/myweb
记录地址
http://192.168.122.30:8080/project/myweb
点击高级
点击Generate
生成 Secret token
877eefe539ec1367338767fb65d24db9
4.构建
选择 Send files or execute command over SSH
5.配置gitlab
1.修复gitlab报错
Urlis blocked: Requests to the local network are not allowed
2.测试 Webhook 配置
Hook executed successfully: HTTP 200
成功
6.推送文件到gitlab(192.168.122.30)
git commit -m "init"
git status
git config --global user.name "lp"
git config --global user.email "1078802338@qq.com"
git config --global core.editor vim
git remote add origin git@192.168.122.50:root/myweb.git
git remote show origin
git branch jenkins
git checkout jenkins
echo '<h3>new line</h3>' >> index.html
git add .
git commit -m "init"
git push origin jenkins