{"id":745,"date":"2020-08-21T09:12:00","date_gmt":"2020-08-21T01:12:00","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=745"},"modified":"2020-08-21T09:12:01","modified_gmt":"2020-08-21T01:12:01","slug":"kubernetes-continues-to-integrate-the-jenkins-pipline","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2020\/08\/kubernetes-continues-to-integrate-the-jenkins-pipline\/","title":{"rendered":"kubernetes\u6301\u7eed\u96c6\u6210jenkins pipline \u811a\u672c\u793a\u4f8b\u3002Java\u3001node.js\u3001vue \u524d\u7aef\u3002"},"content":{"rendered":"\n
\/\/ \u5b9a\u4e49\u53c2\u6570\u5316\u6784\u5efa\u7684\u53c2\u6570\nproperties([\n parameters([\n booleanParam(name: 'ApiManage', defaultValue: false, description: '\u662f\u5426\u90e8\u7f72api-manage'),\n booleanParam(name: 'ApiManageWeb', defaultValue: false, description: '\u662f\u5426\u90e8\u7f72api-manage-web'),\n booleanParam(name: 'AuthManage', defaultValue: false, description: '\u662f\u5426\u90e8\u7f72AuthManage'),\n booleanParam(name: 'AuthManageWeb', defaultValue: false, description: '\u662f\u5426\u90e8\u7f72AuthManageWeb'),\n\t choice(name: 'deployEnv', choices: ['test', 'product'], description: '\u90e8\u7f72test\u73af\u5883\u8fd8\u662fproduct\u73af\u5883'),\n ])\n])\n\n\/\/\u4ee3\u7801\u68c0\u51fa\ndef GetCode(srcUrl,branchName,relativeDir,credentialsId) {\n\tcheckout([\n\t\t$class: 'GitSCM', \n\t\tbranches: [[name: \"${branchName}\"]], \n\t\tdoGenerateSubmoduleConfigurations: false, \n\t\textensions: [\n\t\t\t[$class: 'RelativeTargetDirectory', relativeTargetDir: \"${relativeDir}\"], \n\t\t\t[$class: 'CheckoutOption', timeout: 30], \n\t\t\t[$class: 'CloneOption', noTags: false, reference: '', shallow: false, timeout: 30],\n\t\t\t[$class: 'LocalBranch', localBranch: \"${branchName}\"]\n\t\t], \n\t\tsubmoduleCfg: [], \n\t\tuserRemoteConfigs: [\n\t\t\t[credentialsId: \"${credentialsId}\", url: \"${srcUrl}\"]\n\t\t]\n\t])\n}\n\n\n\/\/\u793a\u4f8b\uff1aPackageBuild(\"wangfeng-service\/wangfeng-assess\",\"registry.cn-beijing.aliyuncs.com\",\"registry-vpc.cn-beijing.aliyuncs.com\",\"wangfeng-assess\")\n\n\/\/ Java \u9879\u76ee\u6784\u5efa\ndef PackageBuild(relativeDir,pomRepoUrl,repoUrl,imageName){\n\tdir(\"${relativeDir}\"){\n\n\t\tdef gitcommitid = sh(returnStdout: true, script:'git rev-parse --short HEAD').trim()\n\t\techo \"=============================================Git-Commit-id: ${gitcommitid}\"\n\t\tdef pom = readMavenPom file: 'pom.xml'\n\t\tsh \"mvn clean && mvn package -DskipTests && \"\n\t\tsh \"docker tag ${pomRepoUrl}\/wangfeng\/${imageName}:${pom.version} ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\tsh \"docker rmi ${pomRepoUrl}\/wangfeng\/${imageName}:${pom.version}\"\n\t\twithCredentials([usernamePassword(credentialsId: 'ali-docker-registry', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUser')]) {\n\t\t\tsh \"docker login --username=${dockerUser} -p ${dockerPassword} ${repoUrl}\"\n\t\t\tsh \"docker push ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\t}\n\t\techo \"=============================================DockerImage: ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n \n\t\tif(params.deployEnv == \"test\"){\n\t\t sh \"kubectl --kubeconfig \/var\/lib\/jenkins\/k8s\/config --context k8s-ali-admin set image deployment\/${imageName} ${imageName}=${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} -n oppc\"\n }\n if(params.deployEnv == \"product\"){\n print \"\u751f\u4ea7\u73af\u5883\u9700\u624b\u52a8\u53d1\u5e03\uff01\"\n\t\t}\n\t}\n}\n\/\/ vue\u524d\u7aef\u6784\u5efa\ndef ManageWebBuild(relativeDir,pomRepoUrl,repoUrl,imageName){\n\tdir(\"${relativeDir}\"){\n\t sh \"npm install --registry=https:\/\/registry.npm.taobao.org\"\n\t if(params.deployEnv == \"test\"){\n sh 'npm run build'\n }\n if(params.deployEnv == \"product\"){\n sh 'npm run build:prod'\n }\n\n\t sh \"\\\\cp -rf dist docker\"\n sh \"cd docker && docker build -t ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\t. \"\t\n\t\tsh \"docker tag ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\tsh \"docker rmi ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\twithCredentials([usernamePassword(credentialsId: 'ali-docker-registry', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUser')]) {\n\t\t\tsh \"docker login --username=${dockerUser} -p ${dockerPassword} ${repoUrl}\"\n\t\t\tsh \"docker push ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\t}\n\t\techo \"=============================================DockerImage: ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n \n\t\tif(params.deployEnv == \"test\"){\n\t\t sh \"kubectl --kubeconfig \/var\/lib\/jenkins\/k8s\/config --context k8s-ali-admin set image deployment\/${imageName} ${imageName}=${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} -n oppc\"\n }\n if(params.deployEnv == \"product\"){\n print \"\u751f\u4ea7\u73af\u5883\u9700\u624b\u52a8\u53d1\u5e03\uff01\"\n\t\t}\n\t}\n}\n\/\/ node\u540e\u7aef\u6784\u5efa\ndef ManageBuild(relativeDir,pomRepoUrl,repoUrl,imageName,versionDir){\n\tdir(\"${relativeDir}\"){\n\t sh \"cd ${versionDir} && pwd && node createVersion.js\"\n sh \"docker build -t ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} . \"\t\n\t\tsh \"docker tag ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\tsh \"docker rmi ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\twithCredentials([usernamePassword(credentialsId: 'ali-docker-registry', passwordVariable: 'dockerPassword', usernameVariable: 'dockerUser')]) {\n\t\t\tsh \"docker login --username=${dockerUser} -p ${dockerPassword} ${repoUrl}\"\n\t\t\tsh \"docker push ${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n\t\t}\n\t\techo \"=============================================DockerImage: ${pomRepoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER}\"\n \n\t\tif(params.deployEnv == \"test\"){\n\t\t sh \"kubectl --kubeconfig \/var\/lib\/jenkins\/k8s\/config --context k8s-ali-admin set image deployment\/${imageName} ${imageName}=${repoUrl}\/wangfeng\/${imageName}:v${BUILD_NUMBER} -n oppc\"\n }\n if(params.deployEnv == \"product\"){\n print \"\u751f\u4ea7\u73af\u5883\u9700\u624b\u52a8\u53d1\u5e03\uff01\"\n\t\t}\n\t}\n}\n\nnode {\n MVNHOME ='\/u01\/install\/apache-maven-3.6.2'\n JAVA_HOME = \"\/u01\/install\/jdk1.8.0_201\"\n NODE_HOME=\"\/u01\/install\/node\"\n \/\/\u5185\u7f51git\u4ed3\n GIT_REPO_URL = 'git@172.17.252.143'\n \/\/\u516c\u7f51\u963f\u91ccdocker\u4ed3\n POM_REPO_URL = 'registry.cn-beijing.aliyuncs.com'\n \/\/\u5185\u7f51\u963f\u91ccdocker\u4ed3\n REPO_URL = 'registry-vpc.cn-beijing.aliyuncs.com'\n \/\/jenkins\u5b9a\u4e49\u62c9\u53d6git\u4ee3\u7801\u51ed\u636e\n JENKINS_GIT_PUT_KEY = 'jenkins-pub-key'\n \n \n if(params.deployEnv == \"test\"){\n \t BRANCH_NAME = 'test'\n }\n if(params.deployEnv == \"product\"){\n \t BRANCH_NAME = 'master'\n }\n \n \n \/\/ \u73af\u5883\u53d8\u91cf\t\n env.PATH = \"${JAVA_HOME}\/bin:${MVNHOME}\/bin:${env.PATH}:${NODE_HOME}\/bin:$PATH\"\n env.JAVA_HOME = \"${JAVA_HOME}\"\n \n \n \/\/ \u62c9\u53d6\u4ee3\u7801\u3001\u7f16\u8bd1\u3001\u6253\u5305\u6784\u5efa\n if( params.ApiManage ) {\n stage('\u90e8\u7f72api-manage') {\n\t\tGetCode(GIT_REPO_URL+\":oppc\/oppcApiManage.git\",BRANCH_NAME,\"oppcApiManage\",JENKINS_GIT_PUT_KEY)\n \t\tManageBuild(\"oppcApiManage\",POM_REPO_URL,REPO_URL,\"api-manage\",\"apiManage\")\n \t}\n }\n if( params.ApiManageWeb ) {\n \t stage('\u90e8\u7f72api-manage-web') {\n GetCode(GIT_REPO_URL+\":oppc\/oppcApiManage.git\",BRANCH_NAME,\"oppcApiManage\",JENKINS_GIT_PUT_KEY)\t\t\n \t \tManageWebBuild(\"oppcApiManage\/apiManageWeb\",POM_REPO_URL,REPO_URL,\"api-manage-web\")\n \t}\n\t} \t\n\t\t\n if( params.AuthManage ) {\n stage('\u90e8\u7f72AuthManage') {\n\t\tGetCode(GIT_REPO_URL+\":oppc\/ommpAuthManage.git\",BRANCH_NAME,\"ommpAuthManage\",JENKINS_GIT_PUT_KEY)\n \t\tManageBuild(\"ommpAuthManage\",POM_REPO_URL,REPO_URL,\"auth-manage\",\"ommpAuthManageApi\")\n \t}\n }\n if( params.AuthManageWeb ) {\n \t stage('\u90e8\u7f72AuthManageWeb') {\n GetCode(GIT_REPO_URL+\":oppc\/ommpAuthManage.git\",BRANCH_NAME,\"ommpAuthManage\",JENKINS_GIT_PUT_KEY)\t\t\n \t \tManageWebBuild(\"ommpAuthManage\/ommpAuthManageWeb\",POM_REPO_URL,REPO_URL,\"auth-manage-web\")\n \t}\n }\n\n }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,17,18],"tags":[],"yoast_head":"\nkubernetes\u6301\u7eed\u96c6\u6210jenkins pipline \u811a\u672c\u793a\u4f8b\u3002Java\u3001node.js\u3001vue \u524d\u7aef\u3002 - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n\n\n\n\n\n\n\n\n\n\n\n