OS:ubuntu18.04
jenkins: 2.277.4
| 服务器ip | 用途 |
| 192.168.233.17 | gitlab服务器 |
| 192.168.233.18 | Jenkins服务器 |
| 192.168.233.195 | 当做后端的nginx服务器 |
1、新建任务
2、输入任务名称以及选择自由风格选项,然后点击确定
3、这里git源码选择基于ssh秘钥的方式认证
4、这里的构建指的是Jenkins在拉完代码后,之后需要做的事。比如传代码到其他服务器,执行重启服务等。这里为了方便演示,仅拷贝一个文件。
然后点击保存,完成任务的创建
5、现在195后端的nginx页面是这样的,之后在gitlab上把页面插入一行test2
root@ubuntu18:~/good# cat index.html test1 test2 root@ubuntu18:~/good# git add index.html root@ubuntu18:~/good# git commit -m index.html [master d1f9216] index.html Committer: rootYour name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly. Run the following command and follow the instructions in your editor to edit your configuration file: git config --global --edit After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 1 insertion(+) root@ubuntu18:~/good# git push Username for 'http://192.168.233.17': root Password for 'http://root@192.168.233.17': Counting objects: 3, done. Writing objects: 100% (3/3), 258 bytes | 258.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://192.168.233.17/root/good.git b3e29f3..d1f9216 master -> master root@ubuntu18:~/good#
6、回到Jenkins上,点击立即构建
7、再访问233.195,发现页面已经多了一行test2。
至此自由风格代码部署成功
pipeline模式部署
Pipline 就是一套运行于 Jenkins 上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程,从而实现单个任务很难实现的复杂流程编排和任务可视化,Pipeline 的实现方式是一套Groovy DSL,任何发布流程都可以表述为一段 Groovy 脚本。
语法:
Stage:阶段,一个 pipline 可以划分为若干个 stage,每个 stage 都是一个操作步骤,
比如 clone 代码、代码编译、代码测试和代码部署,阶段是一个逻辑分组,可以跨多个 node 执行。
Node:节点,每个 node 都是一个 jenkins 节点,可以是 jenkins master 也可以是jenkins agent,node 是执行 step 的具体服务器。
Step:步骤,step 是 jenkins pipline 最基本的操作单元,从在服务器创建目录到构建容器镜像,由各类 Jenkins 插件提供实现,一个 stage 中可以有多个 step,例如: sh “make”
1、新建任务
2、写脚本
3、点击构建
4、把gitlab上index的页面再新增一行:test333
5、访问结果



