下载插件

image-20200719151158815

创建一个pipeline项目

image-20200719175548958

点击下面的流水线语法

image-20200719181407608

到流水线语法的片段生成器里选择Check out from version control

image-20200719181733175

填入仓库和凭证,生成脚本

image-20200719181949111

复制到pipeline脚本里去

然后选择sh:Shell script,生成脚本,复制

image-20200719183109654

然后再选择deploy:Deploy war/ear to a container

image-20200719183350295

然后填写参数,生成

image-20200719183542898

最后的样子就是这样

image-20200719183627199

完整脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pipeline {
agent any

stages {
stage('pull') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '83039753-8e29-49c9-8e1a-f2c33c4cb847', url: 'git@121.89.163.191:root/rubenweicowbeer.git']]])
}
}
stage('build') {
steps {
sh label: '', script: 'mvn clean package'
}
}
stage('publish') {
steps {
deploy adapters: [tomcat8(credentialsId: '15efa4d4-9b32-4c8d-a0b6-2aa89b72191f', path: '', url: 'http://121.89.163.191:8080')], contextPath: null, war: 'target/*.war'
}
}
}
}

然后就可以保存,构建了

如果我们想把pipeline脚本用文件的形式保存在项目目录

那么我们就可以创建一个Jenkinsfile并粘入我们的pipeline脚本

image-20200719191333403

push之后发现已经有了

image-20200719191352948

然后选择Pipeline script from SCM

image-20200719191035863

填写配置

image-20200719191429618

然后构建