You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcm-coordinator-rpc.Jenkinsfile 3.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. def JOB_NAME = "${env.JOB_NAME}"
  2. def BUILD_NUMBER = "${env.BUILD_NUMBER}"
  3. def label = "jenkins-${JOB_NAME}-${BUILD_NUMBER}-${UUID.randomUUID().toString()}"
  4. def code_path = "rpc"
  5. def project_name = "pcm-coordinator-rpc"
  6. podTemplate(label: label, containers: [
  7. containerTemplate(name: 'golang', image: 'golang:1.20.2-alpine3.17', command: 'cat', ttyEnabled: true),
  8. containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
  9. containerTemplate(name: 'kubectl', image: 'jcce/kubectl:1.23.7', command: 'cat', ttyEnabled: true)
  10. ], serviceAccount: 'jenkins', volumes: [
  11. hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
  12. ]) {
  13. node(label) {
  14. // 镜像仓库地址
  15. // def registryUrl = "registry.cn-hangzhou.aliyuncs.com"
  16. def imageEndpoint = "jcce/${project_name}"
  17. stage('拉取代码') {
  18. checkout scmGit(branches: [[name: "*/${branches}"]], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlink-zj', url: 'https://gitlink.org.cn/JointCloud/pcm-coordinator.git']])
  19. echo "获取commit_id 作为镜像标签"
  20. script {
  21. env.imageTag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  22. env.image = "${registryUrl}/${imageEndpoint}:${imageTag}"
  23. env.imageLatest = "${registryUrl}/${imageEndpoint}:latest"
  24. }
  25. }
  26. // stage('代码编译打包') {
  27. // try {
  28. // container('golang') {
  29. // echo "代码编译打包阶段"
  30. // sh """
  31. // cd ${code_path}
  32. // export GOPROXY=https://goproxy.cn
  33. // CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${project_name} ./pcmcore.go
  34. // """
  35. // }
  36. // } catch (exc) {
  37. // println "构建失败 - ${currentBuild.fullDisplayName}"
  38. // }
  39. // }
  40. stage('构建 Docker 镜像') {
  41. withCredentials([[
  42. $class: 'UsernamePasswordMultiBinding',
  43. credentialsId: 'docker-auth',
  44. usernameVariable: 'DOCKER_USER',
  45. passwordVariable: 'DOCKER_PASSWORD'
  46. ]]) {
  47. container('docker') {
  48. echo "构建 Docker 镜像阶段"
  49. sh """
  50. docker login ${registryUrl} -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}
  51. docker build -t ${image} -t ${imageLatest} -f ${code_path}/Dockerfile .
  52. docker push ${image}
  53. docker push ${imageLatest}
  54. docker rmi -f ${image} ${imageLatest}
  55. """
  56. }
  57. }
  58. }
  59. stage('运行 Kubectl 部署到k8s平台') {
  60. withCredentials([file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')]) {
  61. container('kubectl') {
  62. echo "部署应用"
  63. sh """
  64. mkdir -p ~/.kube && cp ${KUBECONFIG} ~/.kube/config
  65. cd ${code_path}
  66. sed -i 's#image_name#${image}#' ${project_name}.yaml
  67. sed -i 's#secret_name#${secret_name}#' ${project_name}.yaml
  68. sed -i 's#nacos_host#${nacos_host}#' ${project_name}.yaml
  69. cat ${project_name}.yaml
  70. kubectl apply -f ${project_name}.yaml
  71. """
  72. }
  73. }
  74. }
  75. stage('清理镜像') {
  76. container('docker') {
  77. sh """
  78. docker rmi -f ${image} ${imageLatest}
  79. """
  80. // cleanWs notFailBuild: true
  81. }
  82. }
  83. }
  84. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.