pipeline {
// 通过agent指定执行节点
// agent any告诉Jenkins该流水线可以运行在任何一个定义好的代理节点上,而不关心它具有什么标签
agent any
environment {
TIMEZONE = "eastern"
TIMEZONE_DS = "${TIMEZONE}_daylight_savings"
}
// 指定全局配置当中的工具
tools {
maven 'maven3.6'
}
options {
// 构建清理配置
buildDiscarder(logRotator(numToKeepStr:'3'))
// 如果流水线中一个阶段把流水线的状态置为了不稳定状态,系统就不会处理剩余的阶段
skipStagesAfterUnstable()
// 打印时间搓
timestamps()
}
triggers {
// 定期执行任务 从周一到周五上午8点开始执行流水线
cron('H 3 * * 1-5')
}
parameters {
string(defaultValue:'Linux',description:'What platform?',name:'platform')
string(defaultValue:'maintainer',description:'Enter user role:',name:'userRole')
}
stages {
stage('echo') {
steps {
// 在流水线中使用参数
echo "User's role = ${params.userRole}"
}
}
stage('Build1') {
steps {
// Get some code from a GitHub repository
git credentialsId: '4738826e-3d34-41f8-8ee7-fb19743952f3', url: 'git@172.19.6.63:heng-tai/xams-bom.git'
// Run Maven on a Unix agent.
sh "mvn clean deploy"
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
stage('Build2') {
steps {
// Get some code from a GitHub repository
git credentialsId: '4738826e-3d34-41f8-8ee7-fb19743952f3', url: 'git@172.19.6.63:heng-tai/xams-common-starter.git'
// Run Maven on a Unix agent.
sh "mvn clean deploy"
// To run Maven on a Windows agent, use
// bat "mvn -Dmaven.test.failure.ignore=true clean package"
}
}
}
// 构建后事件 这个post也可以用于每个stage内最后
post{
always {
echo 'Build stage complete'
// 发送邮件
mail to: 'guanglai.zhou@xquant.com',subject:"Status of pipeline:${currentBuild.fullDisplayName}",body:"${env.BUILD_URL} has result ${currentBuild.result}"
}
success {
echo 'Build successed'
}
}
}
一个声明式Jenkins流水线完整小案例
最新推荐文章于 2024-04-19 10:55:16 发布