1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| def gitlabUrl = "gitlab.ropon.top" def harborUrl = "harbor.ropon.top" def GroupName = "testgo" def projectName = "hellogo" def imageTag = "latest" def kubectlImage = "lachlanevenson/k8s-kubectl:v1.16.9" def branchName = "master" def gitAuthName = "gitlab-auth-user" def harborAuthName = "harbor-auth-user" def sendmsgAuthName = "sendmsg-auth-user" def msgText = "构建完成,请测试"
podTemplate(cloud: 'kubernetes',containers: [ containerTemplate(name: 'docker', image: 'docker:stable', command: 'cat', ttyEnabled: true), containerTemplate(name: 'kubectl', image: "${kubectlImage}", command: 'cat', ttyEnabled: true) ], volumes: [ hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'), hostPathVolume(hostPath: '/root/.kube', mountPath: '/root/.kube') ] )
{ node (POD_LABEL) { stage('pull code') { checkout([$class: 'GitSCM', branches: [[name: "*/${branchName}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${gitAuthName}", url: "http://${gitlabUrl}/${GroupName}/${projectName}.git"]]]) } container('docker') { stage('docker-build') { withCredentials([usernamePassword(credentialsId: "${harborAuthName}", passwordVariable: 'password', usernameVariable: 'username')]) { sh "docker login -u $username -p $password $harborUrl" } sh "docker build -t ${projectName}:${imageTag} ." def imageName = "${projectName}:${imageTag}" def remoteImageName = "${harborUrl}/${GroupName}/${imageName}" sh "docker tag $imageName $remoteImageName" sh "docker push $remoteImageName" sh "docker rmi $imageName" sh "docker rmi $remoteImageName" } } container('kubectl') { stage('k8s deploy') { sh "kubectl --kubeconfig=/root/.kube/config apply -f deployment.yaml" } } stage('send msg') { withCredentials([usernamePassword(credentialsId: "${sendmsgAuthName}", passwordVariable: 'password', usernameVariable: 'username')]) { sh "wget http://panel.ropon.top/soft/sendmsg && chmod +x sendmsg && ./sendmsg $password $username $msgText" } } } }
|