156a073b2856980b8724b5f6f3901264274ffb16.svn-base 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. node {
  2. script {
  3. mysql_addr = '127.0.0.1' // service cluster ip
  4. redis_addr = '127.0.0.1' // service cluster ip
  5. user_addr = '127.0.0.1:30036' // nodeIp : port
  6. }
  7. // 使用 Jenkinsfile 会关联 Git 仓库,代码已经一起拉下来
  8. stage('get commit_id from github') {
  9. echo "first stage: get commit_id"
  10. script {
  11. commit_id = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
  12. }
  13. }
  14. stage('build image') {
  15. echo "second stage: build docker image"
  16. sh "docker build -t aoho/user:${commit_id} section11/user/"
  17. }
  18. stage('push image') {
  19. echo "third stage: push docker image to registry"
  20. sh "docker login -u aoho -p xxxxxx"
  21. sh "docker push aoho/user:${commit_id}"
  22. }
  23. stage('deploy to Kubernetes') {
  24. echo "forth stage: deploy to Kubernetes"
  25. sh "sed -i 's/<COMMIT_ID_TAG>/${commit_id}/' user-service.yaml"
  26. sh "sed -i 's/<MYSQL_ADDR_TAG>/${mysql_addr}/' user-service.yaml"
  27. sh "sed -i 's/<REDIS_ADDR_TAG>/${redis_addr}/' user-service.yaml"
  28. sh "kubectl apply -f user.yaml"
  29. }
  30. stage('http test') {
  31. echo "fifth stage: http test"
  32. sh "cd section11/user/transport && go test -args ${user_addr}"
  33. }
  34. }