pipeline 持续部署到仓库

jenkinsfile

/*
    jenkins 项目名 gprp_mllearning_master_CI
    jenkins GUI上的变量配置

        String: NODE, TAG,REPO_URL, BRANCH, EMAIL, credentialsId

        * JOB_NAME: 项目名
        * NODE: 发布机节点
        * REPO_URL: git项目仓库地址
        * BRANCH: 发布的分支
        * EMAIL: 项目负责人
        * credentialsId: 拉取代码的public key,要有写权限

*/

node(NODE) {
    try{
        compile()
        stage('通知负责人'){
            emailext body: "构建成功 ${BUILD_URL}\r\n", subject: '构建成功 ${JOB_NAME}', to: "${EMAIL}"
        }
    } catch (e) {
        sh "rm -rf .git pom.xml"
        compile()
        stage('通知负责人'){
            emailext body: "构建成功 ${BUILD_URL}\r\n", subject: '构建成功 ${JOB_NAME}', to: "${EMAIL}"
        }
    }
}
def compile(){
    stage('检出代码,编译,打包到仓库'){
        git branch: "${BRANCH}",credentialsId: "${credentialsId}", url: "${REPO_URL}"
    }
    if (BRANCH == "master"){

        sh '''

            if [[ `sed -n '/dependencies/,/dependencies/p' pom.xml| grep 'SNAPSHOT'` ]];then

                exit 1

            fi

        '''

        sh "/usr/local/maven/bin/mvn -Darguments=-Dmaven.test.skip=true release:prepare release:perform -B"
    }else if(BRANCH == "develop"){
        sh "/usr/local/maven/bin/mvn -Dmaven.test.skip=true deploy -U -B"
    }

}

pom.xml

    
        scm:git:ssh://git@gitlab.${HOST}.com/gprp/gprp_cloud_api.git
        scm:git:ssh://git@gitlab.${HOST}.com/gprp/gprp_cloud_api.git
        http://gitlab.${HOST}.com/gprp/gprp_cloud_api/
        v1.0.68
    
    
        
            gprp
            http://nexus.${HOST}doc.com:8081/repository/gprp/
        
        
            gprp-snapshot
            
                http://nexus.${HOST}doc.com:8081/repository/gprp-snapshot/
            
        
    

你可能感兴趣的:(pipeline 持续部署到仓库)