多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
刚才我们都是直接在Jenkins的UI界面编写Pipeline代码,这样不方便脚本维护,建议把Pipeline脚本放在项目中(一起进行版本控制)。 <br/> 步骤如下: **1. 项目中编写脚本** ![](https://img.kancloud.cn/b9/c1/b9c102da4b321e96547344f8831da112_1279x363.jpg) ```groovy pipeline { agent any stages { stage('拉取代码') { steps { checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'ed522e63-9512-4143-a444-1881af6df298', url: 'git@192.168.1.13:itheima_group/web-demo-pipeline.git']]]) } } stage('编译构建') { steps { sh label: '', script: 'mvn clean package' } } stage('项目部署') { steps { deploy adapters: [tomcat8(credentialsId: '133196f5-f991-4892-98b6-df04e4af21cb', path: '', url: 'http://192.168.1.16:8080/')], contextPath: null, war: 'target/*.war' } } } } ``` 编写完成后记得上传到gitlab。 **2. 引用脚本文件** ![](https://img.kancloud.cn/12/00/120023d40e4c07fd1bfe8ec4783aff9f_1275x532.jpg) ![](https://img.kancloud.cn/5e/1b/5e1b9efa7d512e43d50339a0ca3d53df_1264x228.jpg)