Jenkins学习(1)基础关键字

2020-03-08  本文已影响0人  积土成城

Jenkinsfile

pipeline 流水线

持续交付即代码 将持续交付的实现和实施集成到Jenkins中

agent 定义执行环境

指令告诉Jenkins在哪里以及如何执行Pipeline或者Pipeline子集

environment 环境变量

环境变量可以设置全局的, 也可以是阶段(stage)级别的
阶段(stage)级别的环境变量只能在定义变量的阶段(stage)使用

stage 阶段
step 步骤 用来构建、测试和部署应用
retry 重试
timeout 超时
post 完成时工作

持续交付的Pipeline 至少会有三个阶段:构建、测试和部署

Jenkinsfile
pipeline {
    agent any
    stages {
        stage('Build'){
            steps {
                sh 'test'

                retry(3) {
                    sh './flakey-deploy.sh'
                }

                timeout(time: 3, unit: 'MINUTES') {
                    sh './health-check.sh'
                }
            }
           stage('Test') {
               steps {
                    echo 'Testing'
               }
            }
            stage('Deploy') {
                steps {
                    echo 'Deploying'
                }
            }
        }
    }
    post {
        always {
            echo 'This will always run'
        }
        success {
            echo 'This will run only if successful'
        }
        failure {
            echo 'This will run only if failed'
            mail to: 'team@example.com',
                    subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
                    body: "Something is wrong with ${env.BUILD_URL}"
        }
        unstable {
            echo 'This will run only if the run was marked as unstable'
        }
        changed {
            echo 'This will run only if the state of the Pipeline has changed'
            echo 'For example, if the Pipeline was previously failing but is now successful'
        }
    }
}
上一篇 下一篇

猜你喜欢

热点阅读