当前位置:   article > 正文

项目管理使用coding,前端使用ssh自动化部署-持续集成vue3+pnpm_coding自动化部署

coding自动化部署

1.选中coding的中要自动化部署的项目

2.点击创建构建计划 

3. 本项目使用ssh。

4.按照图片上的提示填上去就行 

5. 

6. 

 7.

8. 选择流程配置,将以下代码填写上去就行

  1. def remoteConfig = [:]
  2. remoteConfig.name = "my-remote-server"
  3. remoteConfig.host = "${REMOTE_HOST}"
  4. remoteConfig.allowAnyHosts = true
  5. // 使用 SCP 作为文件传输
  6. remoteConfig.fileTransfer = "scp"
  7. pipeline {
  8. agent any
  9. stages {
  10. stage('安装Node.js') {
  11. steps {
  12. sh 'rm -rf /usr/lib/node_modules/npm/'
  13. dir ('/root/.cache/downloads') {
  14. sh 'wget -nc "https://coding-public-generic.pkg.coding.net/public/downloads/node-linux-x64.tar.xz?version=v16.13.0" -O node-v16.13.0-linux-x64.tar.xz | true'
  15. sh 'tar -xf node-v16.13.0-linux-x64.tar.xz -C /usr --strip-components 1'
  16. // sh 'wget -nc "https://coding-public-generic.pkg.coding.net/public/downloads/node-linux-x64.tar.xz?version=v14.18.2" -O node-v14.18.2-linux-x64.tar.xz | true'
  17. // sh 'tar -xf node-v14.18.2-linux-x64.tar.xz -C /usr --strip-components 1'
  18. // 更多版本:v12.22.7、v17.2.0
  19. }
  20. sh 'node -v'
  21. }
  22. }
  23. stage("检出") {
  24. steps {
  25. checkout([
  26. $class: 'GitSCM',
  27. branches: [[name: env.GIT_BUILD_REF]],
  28. userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]
  29. ])
  30. }
  31. }
  32. stage("安装依赖") {
  33. steps {
  34. sh "pnpm i"
  35. }
  36. }
  37. stage("编译") {
  38. steps {
  39. sh "pnpm build"
  40. }
  41. }
  42. stage('部署') {
  43. steps {
  44. echo '发布中...'
  45. script {
  46. def remote = [:]
  47. remote.name = 'server2'
  48. remote.allowAnyHosts = true
  49. remote.host = "${REMOTE_HOST}"
  50. remote.port = 22
  51. remote.user = "${REMOTE_USER_NAME}"
  52. withCredentials([ sshUserPrivateKey(credentialsId:"${REMOTE_CRED}"
  53. ,keyFileVariable:'SSH_PRIVATE_KEY_PATH')]) {
  54. remote.identityFile = SSH_PRIVATE_KEY_PATH
  55. sshPut remote: remote, from: './dist/.', into: '/html/aia'
  56. sshCommand remote: remote, sudo: true, command: "cp -rf /html/aia/dist/* /html/aia"
  57. sshCommand remote: remote, sudo: true, command: "rm -rf /html/aia/dist"
  58. }
  59. }
  60. echo '发布完成.'
  61. }
  62. }
  63. }
  64. }


9.填写变量 

 10.点击立即构建即可

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号