码迷,mamicode.com
首页 > 其他好文 > 详细

看到了一个pipeline例子,

时间:2018-01-03 11:35:34      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:sonar   style   post   mvn   registry   ref   boolean   ring   message   

pipeline {
    agent any
    options {
        timestamps()
    }
    parameters {
        string(name: GIT_BRANCH, defaultValue: master, description: default build branch)
        booleanParam(name: RUN_SONAR_SCANNER, defaultValue: true, description: run the sonar scanner check.)
    }
    environment {
        MAVEN_IMAGE = maven:3-alpine
        SONAR_SCANNER_IMAGE = cnlinux/sonar-scanner:3.0.3
        SONAR_SERVER = http://10.0.7.1:9000
        DOCKER_REGISTRY = "10.0.7.1:5000"
        APP_NAME = jenkins-jipeline-demo
        DEPLOY_HOST = 10.0.7.1:2376
    }
    stages {
        stage(Checkout) {
            steps {
                git branch: "${params.GIT_BRANCH}", url: https://github.com/opspy/Jenkins-Pipeline-demo.git
            }
        }
        stage(Test) {
            parallel {
                stage (Unit Test) {
                    agent {
                        docker {
                            reuseNode true
                            image ${MAVEN_IMAGE}
                            args -v $HOME/.m2:/root/.m2
                        }
                    }
                    steps {
                        sh mvn test
                        junit **/target/**/*.xml
                    }
                }
                stage (Sonar Scanner) {
                    when {
                        environment name: RUN_SONAR_SCANNER, value: true
                    }
                    agent {
                        docker {
                            reuseNode true
                            image ${SONAR_SCANNER_IMAGE}
                        }
                    }
                    steps {
                        sh sonar-scanner -Dsonar.host.url=${SONAR_SERVER}
                    }
                }
            }
        }
       stage(Build War) {
            agent {
                docker {
                    reuseNode true
                    image ${MAVEN_IMAGE}
                    args -v $HOME/.m2:/root/.m2
                }
            }
            steps {
                sh mvn -Dmaven.test.skip=true clean install
            }
       }
       stage(Docker image) {
            steps {
                sh """
                        mv -f target/*.war deployment/
                        docker build -t ${DOCKER_REGISTRY}/${APP_NAME}:${BUILD_NUMBER} deployment
                        docker push ${DOCKER_REGISTRY}/${APP_NAME}:${BUILD_NUMBER}
                        docker rmi ${DOCKER_REGISTRY}/${APP_NAME}:${BUILD_NUMBER}
                        rm -f deployment/*.war
                """
            }
        }
        stage(‘Deploy‘) {
            steps {
                input message: ‘Are you sure Deployment?‘, ok: ‘Yes‘
                sh"""
                    docker -H ${DEPLOY_HOST} rm -f ${APP_NAME} | true
                    docker -H ${DEPLOY_HOST} run -d --name ${APP_NAME} -p 9090:8080 ${DOCKER_REGISTRY}/${APP_NAME}:${BUILD_NUMBER}
                """
                }
        }
    }
    post {
        always {
            emailext body: """<p>STARTED: Job ‘${env.JOB_NAME} [${env.BUILD_NUMBER}]‘:</p>
                <p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
            subject: "STARTED: Job ‘${env.JOB_NAME} [${env.BUILD_NUMBER}]‘", 
            to: ‘admin@example.com‘
        }
    }
}

 

看到了一个pipeline例子,

标签:sonar   style   post   mvn   registry   ref   boolean   ring   message   

原文地址:https://www.cnblogs.com/fengjian2016/p/8182233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!