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

    parameters {
		string(name:'clusterId', defaultValue: 'yoho-web-gray', 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: '镜像版本')
		string(name:'deployEnv', defaultValue: 'qcloud', description: '部署环境 qcloud,aws,all')
    }
	
	
    //常量参数,初始确定后一般不需更改
    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 projectName 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 upload to cdn"
                    if(params.deployEnv=='qcloud' || params.deployEnv=='all'){
                        //切换kubectl的认证
                        def pyworkdir="${env.WORKSPACE}/Docker-Image-Deplopy/qcloud/qcloudDeploy.py"
                        sh "python ${pyworkdir} ${params.clusterId} ${params.serviceName} ${params.containerName} ${params.imageInfo}"
                    }else {
                        println "qcloud this no need deploy"
                    }
                }
            }
        }

        stage('aws deploy'){
            steps{
                script {
                    println "begin upload to cdn"
                    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 restart"
                    }
                }
            }
        }
    }

	post {
		always {
		    echo "clean up our workspace"
		   deleteDir() /* clean up our workspace */
		}
	}
}