pipeline.Jenkinsfile 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pipeline {
  2. agent any
  3. stages {
  4. stage("检出") {
  5. steps {
  6. checkout(
  7. [$class: 'GitSCM',
  8. branches: [[name: GIT_BUILD_REF]],
  9. userRemoteConfigs: [[
  10. url: GIT_REPO_URL,
  11. credentialsId: CREDENTIALS_ID
  12. ]]]
  13. )
  14. }
  15. }
  16. // 下述演示的过程依赖于模版示例代码内容,您可以根据自己的实际情况调整构建过程
  17. stage('安装依赖') {
  18. steps {
  19. sh "npm install"
  20. }
  21. }
  22. stage('单元测试') {
  23. // 测试框架需要构建环境中预装 Chromium 无头浏览器,在该阶段采用仓库内 Dockerfile 指定的镜像作为测试环境
  24. steps {
  25. sh "npm run test:ci"
  26. // 使用 CODING 插件收集测试报告
  27. junit '*.xml'
  28. }
  29. }
  30. stage('编译') {
  31. steps {
  32. sh "npm run build"
  33. }
  34. }
  35. stage('上传到 COS Bucket') {
  36. steps {
  37. // 配置 COS 信息
  38. sh "coscmd config -a ${COS_SECRET_ID} -s ${COS_SECRET_KEY} -b ${COS_BUCKET_NAME} -r ${COS_BUCKET_REGION}"
  39. // 在此处填写编译构建生成的文件所在路径,这些文件会被上传到 COS Bucket
  40. sh "coscmd upload -r ${COS_UPLOAD_FROM_PATH} /"
  41. // 若您开启了 COS 静态网站,也可以直接访问 https://${COS_BUCKET_NAME}.cos-website.${COS_BUCKET_REGION}.myqcloud.com
  42. // 您可以通过开启 COS 静态网站功能并配置重定向规则实现部署带有路由功能的 SPA,更多内容请参考 https://cloud.tencent.com/document/product/436/32670
  43. echo "上传成功,访问 https://${COS_BUCKET_NAME}.cos-website.${COS_BUCKET_REGION}.myqcloud.com 预览效果"
  44. echo "您也可以访问原域名 https://${COS_BUCKET_NAME}.cos.${COS_BUCKET_REGION}.myqcloud.com/index.html 预览效果"
  45. }
  46. }
  47. }
  48. }