Jenkins学习(1)基础关键字

Jenkinsfile

pipeline 流水线

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

agent 定义执行环境

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

  • 所有在块block中的步骤steps会被Jenkins保存在一个执行队列中。一旦一个执行器executor是可以利用的,这些步骤将会开始执行。
  • 一个工作空间workspace将会被分配,工作空间中会包含来自远程仓库的文件和一些用于Pipeline的工作文件
environment 环境变量

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

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

持续交付的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: '[email protected]',
                    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'
        }
    }
}

你可能感兴趣的:(Jenkins学习(1)基础关键字)