Jenkinsfile 3.18 KB
#!groovy
pipeline {
    agent { label 'master' }

    parameters {
		string(name:'callBack', defaultValue: 'noNeedCallBack', description: '回调服务地址')
        choice(name:'clusterId',choices:'aws\nyoho-web-gray\nyoho-ops\nyoho-web\nyoho-media\n', description: '集群的信息')
		string(name:'serviceName', defaultValue: 'yoho-app-web', description: '服务名称	')
		string(name:'containerName', defaultValue: 'yoho-app-web', description: '容器名称')
		string(name:'imageInfo', defaultValue: 'yohobuy-core/yohobuywap-node:hotfix-share-20181221134254', description: '镜像版本')
		choice(name:'deployEnv',choices:'aws\nqcloud\nall\n', description: '部署的集群信息')
    }
	
	
    //常量参数,初始确定后一般不需更改
    environment{
        CRED_ID='2cb1761b-b258-4e3b-843f-8f0dab16d770'
        QA_EMAIL='jimi.ji@yoho.cn'
        AWS_IMAGE='860721417875.dkr.ecr.cn-north-1.amazonaws.com.cn'
        QCLOUD_IMAGE='ccr.ccs.tencentyun.com'
    }
	
    options {
        //保持构建的最大个数
        buildDiscarder(logRotator(numToKeepStr: '20'))
    }
	
    stages {
        stage('Define para'){
            steps{
                script {
					echo "print the para callBack is : ${params.callBack}......"
                    echo "print the para clusterId is : ${params.clusterId}......"
                    echo "print the para projectGitGroup is : ${params.serviceName}......"
                    echo "print the para deployName is : ${params.containerName}......"
                    echo "print the para branch is : ${params.imageInfo}......"
                    echo "print the para isNeedCdn is : ${params.deployEnv}......"
                }
            }
        }

        stage('qcloud deploy'){
            steps{
                script {
                    println "begin qcloud deploy"
                    if(params.deployEnv=='qcloud' || params.deployEnv=='all'){
                        //切换kubectl的认证
                        def pyworkdir="${env.WORKSPACE}/Docker-Image-Deplopy/qcloud/qcloudDeploy.py"
                        sh "python -u ${pyworkdir} ${params.clusterId} ${params.serviceName} ${params.containerName} ${params.imageInfo}"
                    }else {
                        println "qcloud this no need deploy"
                    }
                }
            }
        }

        stage('aws deploy'){
            steps{
                script {
                    println "begin aws deploy"
                    if(params.deployEnv=='aws' || params.deployEnv=='all'){
                        //切换kubectl的认证
                        def shellworkdir="${env.WORKSPACE}/Docker-Image-Deplopy/aws/awsdeploy.sh"
                        sh "sh ${shellworkdir} ${params.serviceName} ${params.imageInfo}"
                    }else {
                        println "aws this no need deploy"
                    }
                }
            }
        }
    }

	post {
		always {
			script {
				echo "clean up our workspace,and send to callBack"
				deleteDir() /* clean up our workspace */
				if(params.callBack!='noNeedCallBack'){
					sh "curl '${params.callBack}&status=${currentBuild.currentResult}&jobID=${JOB_NAME},${BUILD_NUMBER}'"
				}
			}
		}
	}
}