开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第3天,点击查看活动详情
1.创建jenkins的job任务
1.1.实现jenkins+shell集成
1.1.1.新建一个job任务
| ip | 用途 |
|---|---|
| 192.168.146.111 | jenkins |
| 192.168.146.112 | gitlab |
1.1.2.创建一个freestyle project
1.1.4.点击立即构建
1.1.5.查看构建详情
1.1.6.查看文件存放路径
[root@jenkins~]# cd /var/lib/jenkins/work
workflow-libs/ workspace/
[root@jenkins~]# cd /var/lib/jenkins/workspace/
[root@jenkins/var/lib/jenkins/workspace]# ls
freestyle-jobs1
[root@jenkins/var/lib/jenkins/workspace]# cd freestyle-jobs1/
[root@jenkins/var/lib/jenkins/workspace/freestyle-jobs1]# ls
file1
1.2.实现jenkins+gitlab集成
准备一个monitor监控网站用作发布项目
1.2.1.在gitlab上配置一个公钥
将jenkins的公钥导入到gitlab中
[root@jenkins~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:V9mGO7hgaZxW7cO0FI+CpDgBrZziVpugWkPlEF5rkfU root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| o++o. . . |
| ...+= + . . B |
| ..*= . E o O + |
|..=o.. . + O + |
|ooo o S o B |
|.ooo + o . o |
|o. . . |
|. |
| |
+----[SHA256]-----+
[root@192.168.100.148~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAt2zMYREji6CEDNnj0eu35u77uWcYiqjk1vRkNNReG2gnWCy9VL8lBIKKiqssoKJE9X0SuOCiASi9FV3PgLfeBpQAGYvGWXd43xMitBq0sMvgq8O7m1Gm9r+UiyuAXh2rwpIA4j4sweOls6Nskk6Zcp2qO+fYEDXtXCbdccgdXrQFsJt53XTWUnvPylRkqt5vtzM7amLYdY+bTy44IsCaLIoytghswAH9xbk9z8B4nnxg6dtVhQNd58uj55SXGFOBBcQ40kDxzrgcNb+sgjpKHmIBr4QLf83P0IX3f8/8AbhktElO7t/pHXKW+aNInSL5TAtFSuiOYLuF5L862PV1 root@localhost.localdomain
1.2.2.新建一个项目
1.初始化git仓库
[root@jenkins~]# mkdir monitor
[root@jenkins~/monitor]# touch file{1..10}
[root@jenkins~/monitor]# git init
初始化空的 Git 版本库于 /root/monitor/.git/
2.Git全局变量
[root@jenkins~/monitor]# git config --global user.name "Administrator"
[root@jenkins~/monitor]# git config --global user.email "admin@example.com"
3.添加远程仓库
[root@jenkins~/monitor]# git remote -v
[root@jenkins~/monitor]# git remote add origin git@gitlab.wangzx.com:kaifa1/monitor.git
3.提交本地代码
[root@jenkins~/monitor]# git add .
[root@jenkins~/monitor]# git commit -m "首次提交"
[master 662d26e] add README
9 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file10
create mode 100644 file2
create mode 100644 file3
create mode 100644 file4
create mode 100644 file5
create mode 100644 file6
create mode 100644 file7
create mode 100644 file8
create mode 100644 file9
4.推送至远程仓库
[root@jenkins~/monitor]# git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 230 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To git@gitlab.wangzx.com:kaifa1/app-24983.git
9bce836..7a0a74e master -> master
1.2.4.jenkins新建一个项目
1.2.5.添加私钥与给gitlab建立连接
源码管理选择git然后添加一个私钥
类型选择ssh,通过私钥进行连接
[root@jenkins~/monitor]# cat ~/.ssh/id_rsa