2 Star 3 Fork 3

coolops / jenkins-shareLibrary

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
cool-ops 提交于 2020-04-24 14:21 . Update Jenkinsfile
//String workspace "/opt/jenkins/workspace"
// 配置共享库
@Library('myLib')
// 引用共享库中的方法
def tools = new org.devops.tools()
def build = new org.devops.build()
def deploy = new org.devops.deploy()
// 定义变量
String buildType = env.buildType
String buildShell = env.buildShell
String deployHosts = env.deployHosts
// Pipeline
pipeline {
// 指定在哪个节点上执行pipeline
agent any
//agent{
// node{
// label "master" // 指定运行节点的标签或者名称
// customWorkspace "${workspace}" // 指定运行的工作目录(可选)
// }
//}
// 设置环境变量
environment{
auth = 'joker'
}
// 设置参数
parameters {
// 字符串类型参数,使用的时候:${params.ENV}
string(name: 'ENV', defaultValue: 'PRE', description: '预发环境')
// 布尔类型参数
booleanParam(name: 'DEBUG_BUILD', defaultValue: true, description: '')
}
// 获取自动安装或者手动安装的环境变量
//tools {
// maven "M3"
//}
// 指定运行的选项(可选)
options {
timestamps() // 日志会有时间
skipDefaultCheckout() // 删除隐式checkout scm语句
disableConcurrentBuilds() //禁止并行
timeout(time:1,unit:'HOURS') //设置流水线超时时间
}
// 构建阶段
stages {
// 下载代码
stage("GetCode"){
// 步骤
steps{
// 设置步骤超时时间
timeout(time:5,unit:'MINUTES'){
script{
// println("获取代码")
tools.PrintMes("获取代码",'red')
}
}
}
}
stage("Build"){
steps{
timeout(time:20,unit:'MINUTES'){
script{
// println("代码打包")
tools.PrintMes("代码打包",'blue')
// build.Build(buildType,buildShell)
}
}
}
}
stage("CodeScanner"){
steps{
timeout(time:30,unit:'MINUTES'){
script{
// println("代码扫描")
tools.PrintMes("代码扫描",'green')
}
}
}
}
}
// 构建后的操作
post {
always {
script{
println("always:不论构建成功与否都会执行")
}
}
success {
script{
println("success:只有构建成功才会执行")
currentBuild.description = "\n构建成功!"
deploy.AnsibleDeploy("${deployHosts}","-m ping")
}
}
failure {
script{
println("failure:只有构建失败才会执行")
currentBuild.description = "\n构建失败!"
}
}
aborted {
script{
println("aborted:只有取消构建才会执行")
currentBuild.description = "\n构建取消!"
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coolops/jenkins-shareLibrary.git
git@gitee.com:coolops/jenkins-shareLibrary.git
coolops
jenkins-shareLibrary
jenkins-shareLibrary
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891