You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* 定义一个流水线来自动化不同的阶段任务。
* 流水线中包含多个阶段( stages) , 每个阶段包含多个步骤( steps) 。
* 每个阶段旨在完成特定的任务,例如拉取代码、打包、质量检测等。
*/
pipeline {
agent any // 指定流水线运行的代理, any表示可以在任何可用的agent上运行
stages { // 定义流水线中的各个阶段
stage ( '拉取git仓库代码' ) { // 阶段1: 从Git仓库拉取代码
steps {
checkout scmGit ( branches: [ [ name: '${tag}' ] ] , extensions: [ ] , userRemoteConfigs: [ [ url: 'https://git.mashibing.com/msb_134187/ljj_spring_test.git' ] ] )
}
}
stage ( 'maven打包' ) { // 阶段2: 使用maven进行应用打包
steps {
echo 'maven打包--成功' // 打印信息表示打包阶段成功完成
}
}
stage ( 'sonar质量检测' ) { // 阶段3: 使用Sonar进行代码质量检测
steps {
echo 'sonar质量检测--成功' // 打印信息表示质量检测阶段成功完成
}
}
stage ( '构建镜像' ) { // 阶段4: 构建Docker镜像
steps {
echo '构建镜像--成功' // 打印信息表示镜像构建阶段成功完成
}
}
stage ( '推送镜像到Harbor' ) { // 阶段5: 将构建的镜像推送至Harbor仓库
steps {
echo '推送镜像到Harbor--成功' // 打印信息表示镜像推送阶段成功完成
}
}
stage ( 'ssh到服务器' ) { // 阶段6: 通过ssh连接到目标服务器
steps {
echo 'ssh到服务器--成功' // 打印信息表示ssh连接阶段成功完成
}
}
stage ( '从Harbor仓库拉取镜像' ) { // 阶段7: 从Harbor仓库拉取镜像到目标服务器
steps {
echo '从Harbor仓库拉取镜像--成功' // 打印信息表示镜像拉取阶段成功完成
}
}
stage ( '执行脚本启动容器' ) { // 阶段8: 执行脚本在服务器上启动容器
steps {
echo '执行脚本启动容器--成功' // 打印信息表示容器启动阶段成功完成
}
}
}
}