Jenkinsfile 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. pipeline {
  2. agent any
  3. options {
  4. skipDefaultCheckout true
  5. }
  6. stages {
  7. stage('checkout') {
  8. steps {
  9. checkout scm
  10. }
  11. }
  12. stage('npm install') {
  13. steps {
  14. script {
  15. sh "docker run -i --rm -v ${env.WORKSPACE}:/usr/src/workspace -w /usr/src/workspace mayan31370/docker-image-nodejs:14 cnpm install"
  16. }
  17. }
  18. }
  19. stage('npm build') {
  20. steps {
  21. script {
  22. sh "docker run -i --rm -v ${env.WORKSPACE}:/usr/src/workspace -w /usr/src/workspace mayan31370/docker-image-nodejs:14 cnpm run build:h5"
  23. }
  24. }
  25. }
  26. stage('build docker image') {
  27. steps {
  28. script {
  29. sh "aws ecr get-login-password --region cn-north-1 | docker login --username AWS --password-stdin 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn"
  30. sh "docker build -t aibaidu/arrive-h5 ."
  31. }
  32. }
  33. }
  34. stage('push docker image') {
  35. steps {
  36. script {
  37. sh "docker tag aibaidu/h5:latest 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn/aibaidu/arrive-h5:latest"
  38. sh "docker push 226381024927.dkr.ecr.cn-north-1.amazonaws.com.cn/aibaidu/arrive-h5:latest"
  39. }
  40. }
  41. }
  42. // stage('deploy') {
  43. // steps {
  44. // script {
  45. // sh "ssh -o StrictHostKeyChecking=no aibaidu-admin './deploy-h5.sh'"
  46. // }
  47. // }
  48. // }
  49. stage('Send notify'){
  50. steps{
  51. script{
  52. def content = "### 公众号H5\n<font color='info'>部署完成</font>" + getChangeString()
  53. sh "curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=743fe5f4-d4cf-4906-8aa5-93353a4287da' -H 'Content-Type: application/json' -d '{\"msgtype\": \"markdown\",\"markdown\": {\"content\": \"${content}\",\"mentioned_list\":[\"@all\"]}}'"
  54. }
  55. }
  56. }
  57. }
  58. }
  59. @NonCPS
  60. def getChangeString() {
  61. MAX_MSG_LEN = 100
  62. def changeString = ""
  63. echo "Gathering SCM changes"
  64. def changeLogSets = currentBuild.changeSets
  65. for (int i = 0; i < changeLogSets.size(); i++) {
  66. def entries = changeLogSets[i].items
  67. for (int j = 0; j < entries.length; j++) {
  68. def entry = entries[j]
  69. truncated_msg = entry.msg.take(MAX_MSG_LEN)
  70. changeString += " - ${truncated_msg} [${entry.author}]\n"
  71. }
  72. }
  73. if (!changeString) {
  74. changeString = " - No new changes"
  75. }
  76. return changeString
  77. }