jenkins持续集成jenkinsfile

版权声明:wzhu https://blog.csdn.net/AndyMocan/article/details/82992950
node {
    stage("clean") {
        cleanWs()
    }
    def mvnHome = env.MAVEN_HOME
    stage('Preparation') {
        checkout([$class                           : 'GitSCM',
                  branches                         : [[name: "*/${env.GIT_BRANCH}"]],
                  doGenerateSubmoduleConfigurations: false, extensions: [],
                  submoduleCfg                     : [],
                  userRemoteConfigs                : [[credentialsId: 'db7c9c34-97d4-4a90-916d-6cb9a53b2a17', url: '[email protected]:xx/xx.git']]
        ])
    }
    if (env.IS_MODIFY_VERSION == "true") {
        stage('modify_version') {
            sh "mvn versions:set -DoldVersion=* -DnewVersion=${XX_VERSION} -DprocessAllModules=true -DallowSnapshots=true"
        }
        stage("version_commit") {
            if ("$GIT_BRANCH" != "null") {
                sh """
            git status
            git config --global user.name "wangzhu"
            git config --global user.email "[email protected]"
            git add -u
            git commit -m "modify_version"
            git push origin HEAD:refs/heads/$GIT_BRANCH
            """
            }
        }
        stage("deploy") {
            sh "mvn clean deploy -Dmaven.test.skip=ture"
        }
    }
    stage('Build') {
        if (isUnix()) {
            sh "'${mvnHome}/bin/mvn' -Dmaven.test.skip=ture -Dmaven.test.failure.ignore clean package "
        } else {
            bat(/"${mvnHome}\bin\mvn" -Dmaven.test.skip=ture -Dmaven.test.failure.ignore clean package /)
        }
    }
    stage('docker_build') {
        parallel auth: {
            sh 'docker build --build-arg APOLLO_ENV=${APOLLO_ENV} --build-arg APOLLO_META=${APOLLO_META} --build-arg xx_VERSION=${xx_VERSION} -t 192.168.31.201:5000/xx-auth-server ./xx-auth-server'
            sh 'docker push 192.168.31.201:5000/xx-auth-server'
        }, zuul: {
            sh 'docker build --build-arg APOLLO_ENV=${APOLLO_ENV} --build-arg APOLLO_META=${APOLLO_META} --build-arg xx_VERSION=${xx_VERSION} -t 192.168.31.201:5000/xx-zuul-server ./xx-zuul-server'
            sh 'docker push 192.168.31.201:5000/xx-zuul-server'
        }
    }
    stage("docker_run") {
        sh """
           docker-compose down 
           docker-compose up -d
           """
    }
    stage('Results') {
        junit '**/target/surefire-reports/TEST-*.xml'
    }
}

猜你喜欢

转载自blog.csdn.net/AndyMocan/article/details/82992950