Jenkinsfile 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. def git_auth="d4b4c06c-7a45-4969-a06d-8363858e81cd"
  2. def git_url="http://10.68.0.122:3000/fanyijian/k8s.git"
  3. def jenkins_home="/var/jenkins_home/workspace/k8s/"
  4. def xy_image="registry-vpc.cn-beijing.aliyuncs.com/xinyue-jenkins/"
  5. def release="${BUILD_NUMBER}"
  6. def projectList = project_name.split(",")
  7. ansiColor('xterm') {
  8. node {
  9. stage('pull code') {
  10. echo "\u001B[32m############开始拉取代码############\u001B[0m"
  11. checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
  12. }
  13. stage('build images') {
  14. for (int i = 0; i < projectList.length ; i++) {
  15. echo "\u001B[32m############正在build images,项目名为:${projectList[i]}############\u001B[0m"
  16. sh "docker build -t ${xy_image}${projectList[i]}:${release} -f ${jenkins_home}${projectList[i]}/Dockerfile ${jenkins_home}${projectList[i]}"
  17. }
  18. }
  19. stage('push aliyuncs registry') {
  20. for (int i = 0; i < projectList.length ; i++) {
  21. echo "\u001B[32m############正在推送镜像,项目名为:${projectList[i]}############\u001B[0m"
  22. sh "docker push ${xy_image}${projectList[i]}:${BUILD_NUMBER}"
  23. }
  24. }
  25. stage('push aliyuncs registry') {
  26. for (int i = 0; i < projectList.length ; i++) {
  27. sh "cd ${jenkins_home}"
  28. sh "chmod +x ${jenkins_home}jenkins.py"
  29. sh "python3 jenkins.py ${projectList[i]}"
  30. }
  31. }
  32. }
  33. }