Jenkinsfile 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. pipeline {
  2. agent any
  3. options {
  4. timeout(time: 10, unit: 'MINUTES')
  5. }
  6. stages {
  7. stage('检出') {
  8. steps {
  9. checkout([$class: 'GitSCM', branches: [[name: env.GIT_BUILD_REF]],
  10. userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]])
  11. }
  12. }
  13. stage('安装依赖') {
  14. steps {
  15. echo '安装依赖中...'
  16. sh 'cd api && npm i'
  17. sh 'cd dashboard && npm i'
  18. echo '安装依赖完成.'
  19. }
  20. }
  21. stage('部署') {
  22. steps {
  23. echo '部署中...'
  24. withCredentials([string(credentialsId: '328ecbdc-6b00-465b-9a0a-f5521cf561cc', variable: 'TENCENT_CLOUD_CREDENTIAL')]) {
  25. script{
  26. if (env.TENCENT_CLOUD_CREDENTIAL == '{}') {
  27. error('临时授权已失效,请前往凭据管理重新授权。')
  28. }
  29. }
  30. sh 'echo "${TENCENT_CLOUD_CREDENTIAL}" > .env_temp'
  31. sh 'serverless | tee console.log'
  32. withCredentials([usernamePassword(credentialsId: "${env.CCI_CURRENT_PROJECT_COMMON_CREDENTIALS_ID}", passwordVariable: 'password', usernameVariable: 'userName')]) {
  33. // 发公告
  34. sh 'echo content=$(grep url console.log | head -1) | curl --user ${userName}:${password} https://${CCI_CURRENT_TEAM}.coding.net/api/project/${PROJECT_ID}/tweet -d@-'
  35. }
  36. sh 'rm .env_temp'
  37. }
  38. echo '部署完成'
  39. }
  40. }
  41. }
  42. }