Showing
1 changed file
with
122 additions
and
0 deletions
Docker-Build-And-Deploy/Jenkinsfile
0 → 100644
1 | +#!groovy | ||
2 | +pipeline { | ||
3 | + agent { label 'master' } | ||
4 | + | ||
5 | + parameters { | ||
6 | + choice(name:'clusterId',choices:'aws\nyoho-web-gray\nyoho-ops\nyoho-web\nyoho-media\nyoho-java\n', description: '集群的信息') | ||
7 | + string(name:'projectName', defaultValue: 'yoho-api-doc', description: 'GITLAB应用名称') | ||
8 | + string(name:'projectGitGroup', defaultValue: 'fe', description: 'GITLAB所在的组') | ||
9 | + string(name:'deployName', defaultValue: 'yoho-api-doc', description: '应用名称') | ||
10 | + string(name:'imageSource', defaultValue: 'yoho-ops', description: '镜像存储的仓库') | ||
11 | + string(name:'branch', defaultValue: 'master', description: 'git分支名称') | ||
12 | + } | ||
13 | + | ||
14 | + | ||
15 | + //常量参数,初始确定后一般不需更改 | ||
16 | + environment{ | ||
17 | + QA_EMAIL='jimi.ji@yoho.cn' | ||
18 | + NODE_ENV='production' | ||
19 | + KUBERNETES_DEPLOY_YAML='git@git.yoho.cn:docker/k8s-deploy-yaml.git' | ||
20 | + IMAGEVERSION="""${sh(returnStdout: true,script: 'date +"%Y%m%d%H%M%S"')}""" | ||
21 | + } | ||
22 | + | ||
23 | + options { | ||
24 | + //保持构建的最大个数 | ||
25 | + buildDiscarder(logRotator(numToKeepStr: '20')) | ||
26 | + } | ||
27 | + | ||
28 | + stages { | ||
29 | + stage('init envrionment ') { | ||
30 | + steps { | ||
31 | + script { | ||
32 | + if(params.projectName==''){ | ||
33 | + error "no project ${params.projectName}" | ||
34 | + } | ||
35 | + PROJECT_WORK_DIR="${env.WORKSPACE}/${params.projectName}" | ||
36 | + QCLOUD_IMAGE_STORE="ccr.ccs.tencentyun.com/${params.imageSource}/${params.deployName}:${IMAGEVERSION}" | ||
37 | + if(fileExists("${PROJECT_WORK_DIR}/")){ | ||
38 | + echo "starting delete the dir ${PROJECT_WORK_DIR}" | ||
39 | + sh "rm -rf ${PROJECT_WORK_DIR}" | ||
40 | + } | ||
41 | + } | ||
42 | + echo "PRINT THE PARA projectName ${params.projectName}......" | ||
43 | + echo "PRINT THE PARA projectGitGroup ${params.projectGitGroup}......" | ||
44 | + echo "PRINT THE PARA deployName ${params.deployName}......" | ||
45 | + echo "PRINT THE PARA imageSource ${params.imageSource}......" | ||
46 | + echo "PRINT THE PARA clusterId ${params.clusterId}......" | ||
47 | + echo "PRINT THE PARA branch ${params.branch}......" | ||
48 | + echo "PRINT THE PARA PROJECT_WORK_DIR ${PROJECT_WORK_DIR}......" | ||
49 | + echo "PRINT THE PARA QCLOUD_IMAGE_STORE ${QCLOUD_IMAGE_STORE}......" | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + stage('git clone code') { | ||
54 | + steps { | ||
55 | + script { | ||
56 | + echo "starting check the project ${PROJECT_WORK_DIR}" | ||
57 | + // sh "git clone -b ${params.branch} git@git.yoho.cn:${params.projectGitGroup}/${params.projectName}.git ${PROJECT_WORK_DIR}" | ||
58 | + // echo "starting check the project {params.projectName}" | ||
59 | + // if(!fileExists("${PROJECT_WORK_DIR}/docker.sh")){ | ||
60 | + // echo "you need docker.sh file in project ${params.projectName}" | ||
61 | + // error "you need docker.sh file in project ${params.projectName}" | ||
62 | + // } | ||
63 | + // if(!fileExists("${PROJECT_WORK_DIR}/Dockerfile")){ | ||
64 | + // echo "you need Dockerfile file in project ${params.projectName}" | ||
65 | + // error "you need Dockerfile file in project ${params.projectName}" | ||
66 | + // } | ||
67 | + } | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + // stage('build project') { | ||
72 | + // steps { | ||
73 | + // script { | ||
74 | + // sh "sh ${PROJECT_WORK_DIR}/docker.sh ${PROJECT_WORK_DIR}" | ||
75 | + // } | ||
76 | + // } | ||
77 | + // } | ||
78 | + | ||
79 | + // stage('build and push images to qcloud') { | ||
80 | + // steps { | ||
81 | + // script { | ||
82 | + // sh "docker build -t ${QCLOUD_IMAGE_STORE} ${PROJECT_WORK_DIR}" | ||
83 | + // sh "docker push ${QCLOUD_IMAGE_STORE}" | ||
84 | + // } | ||
85 | + // } | ||
86 | + // } | ||
87 | + | ||
88 | + // stage('deploy to qcloud') { | ||
89 | + // steps { | ||
90 | + // script { | ||
91 | + // if(params.callBack!='noNeedDeploy'){ | ||
92 | + // build job: 'Docker-Image-Deplopy', parameters: [ | ||
93 | + // string(name: 'callBack', value: "noNeedCallBack"), | ||
94 | + // string(name: 'clusterId', value: "${params.clusterId}"), | ||
95 | + // string(name: 'serviceName', value: "${params.deployName}"), | ||
96 | + // string(name: 'containerName', value: "${params.deployName}"), | ||
97 | + // string(name: 'imageInfo', value: "${QCLOUD_IMAGE_VERSION}"), | ||
98 | + // string(name: 'deployEnv', value: 'qcloud')] | ||
99 | + // } | ||
100 | + // } | ||
101 | + // } | ||
102 | + // } | ||
103 | + } | ||
104 | + | ||
105 | + // post { | ||
106 | + // always { | ||
107 | + // script { | ||
108 | + // echo "Pipeline is done,begin send mail" | ||
109 | + // deleteDir() | ||
110 | + // if(params.callBack!='noNeedCallBack'){ | ||
111 | + // sh "curl '${params.callBack}&status=${currentBuild.currentResult}&jobID=${JOB_NAME},${BUILD_NUMBER}'" | ||
112 | + // } | ||
113 | + // mail to: "${env.QA_EMAIL},${params.userMail}", | ||
114 | + // subject: "PineLine '${JOB_NAME}' (${BUILD_NUMBER}),构建结果: ${currentBuild.currentResult}", | ||
115 | + // body: "构建的内容为:${params.projectName},提交人员:${params.userMail}" | ||
116 | + // } | ||
117 | + // } | ||
118 | + // } | ||
119 | +} | ||
120 | + | ||
121 | + | ||
122 | + |
-
Please register or login to post a comment