Jenkinsfile 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. pipeline {
  2. agent any
  3. environment {
  4. DEPLOY_SERVER = "greentech@101.200.76.30"
  5. DEPLOY_REPO_PATH = "/home/greentech/services/reverse_osmosis_model"
  6. HARBOR_URL = "172.16.0.165:5000/simulations"
  7. IMAGE_NAME = "reverse_osmosis_model"
  8. }
  9. stages {
  10. stage('获取commit哈希') {
  11. steps {
  12. git branch: "${APP_GIT_BRANCH}",
  13. url: "${APP_GIT_URL}",
  14. credentialsId: "git-public"
  15. }
  16. }
  17. stage('拉取代码') {
  18. steps {
  19. withCredentials([usernamePassword(
  20. credentialsId: 'gpu2key',
  21. usernameVariable: 'USER',
  22. passwordVariable: 'PWD'
  23. )]) {
  24. sh """
  25. sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
  26. cd ${DEPLOY_REPO_PATH} &&
  27. git pull origin ${APP_GIT_BRANCH}
  28. "
  29. """
  30. }
  31. }
  32. }
  33. stage('构建并推送镜像') {
  34. steps {
  35. script {
  36. def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
  37. withCredentials([usernamePassword(
  38. credentialsId: 'gpu2key',
  39. usernameVariable: 'USER',
  40. passwordVariable: 'PWD'
  41. )]) {
  42. sh """
  43. sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
  44. cd ${DEPLOY_REPO_PATH} &&
  45. export HARBOR_URL=${HARBOR_URL} &&
  46. export IMAGE_NAME=${IMAGE_NAME} &&
  47. export GIT_COMMIT_SHORT=${gitCommitShort} &&
  48. chmod +x build.sh &&
  49. ./build.sh
  50. "
  51. """
  52. }
  53. }
  54. }
  55. }
  56. stage('部署到测试环境') {
  57. steps {
  58. script {
  59. def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
  60. withCredentials([usernamePassword(
  61. credentialsId: 'gpu2key',
  62. usernameVariable: 'USER',
  63. passwordVariable: 'PWD'
  64. )]) {
  65. sh """
  66. sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
  67. export GIT_COMMIT_SHORT=${gitCommitShort}
  68. cd ${DEPLOY_REPO_PATH} &&
  69. docker compose pull && docker compose up -dV
  70. "
  71. """
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }