Pipeline
docker运行
pipeline {
agent {docker 'python'}
stages {
stage('build') {
step {
sh 'python --version'
}
}
}
}
Deploy阶段重试3次flask-deploy.sh直到成功,执行health-check.sh超时执行3分钟
pipeline {
agent any
stages {
stage('Deploy') {
steps {
retry(3) {
sh './flask-deploy.sh'
}
timeout(time: 3,unit: 'MINUTES') {
sh './health-check.sh'
}
}
}
}
}
Deploy阶段重试执行5次flask-deploy.sh直到成功,如果这个时间过长,3分钟超时
pipeline {
agent any
stages {
stage('Deploy') {
steps {
timeout(time: 3,unit: 'MINUTES') {
retry(5) {
sh './flask-deploy.sh'
}
}
}
}
}
}
当管道执行完成,可能需要根据管道的一些结果来进行处理后续清理工作,这里在post中完成。
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'echo "Fail";exit 1'
}
}
}
post {
always {
echo "This will always run"
}
success {
echo "This will run only if successful"
}
failure {
echo "This will run only if failed"
}
unstable {
echo "This will run only if run was marked as unstable"
}
changed {
echo 'This will run only if the state of pipeline has changed'
}
}
}
使用环境变量
pipeline {
agent any
environment {
DISABLE_AUTH='true'
DB_ENGINE='mysql'
}
stages {
stage('Build') {
steps {
sh 'printenv'
}
}
}
清理和通知
pipeline {
agent any
stages {
stage('no-op') {
steps {
sh 'ls'
}
}
}
post {
always {
echo 'one way or another,i have finished'
deleteDir() /* clean up our workspace */
}
failure {
mail to: 'test@gmail.com',
subject: 'Failed Pipeline: ${currentBuild.fullDisplayName}',
body: 'Something is wrong with ${env.BUID_URL}'
}
}
}
部署
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building'
}
}
stage('Test') {
steps {
echo 'Testing'
}
}
stage('Deploy') {
steps {
echo 'Deploying'
}
}
}
}
交互部署
pipeline {
agent any
stages {
stage('Deplay - dev') {
steps {
sh 'echo "deploy dev"'
}
}
stage('Sanity check') {
steps {
input "R U OK?"
}
}
stage('Deploy - production') {
steps {
sh 'echo "deploy production"'
}
}
}
}