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