看到了一个pipeline例子,

Posted fengjian1585

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了看到了一个pipeline例子,相关的知识,希望对你有一定的参考价值。

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: ‘[email protected]‘
        }
    }
}

 

以上是关于看到了一个pipeline例子,的主要内容,如果未能解决你的问题,请参考以下文章

linux管道(pipeline)

linux12Devops --> 09Pipeline简介

Jenkins

片段内的Android TabHost

将 Sklearn GridSearchCV 与 Pipeline 一起使用时如何传递权重

如何创建片段以重复变量编号中的代码行