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

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

2.点击创建构建计划 

3. 本项目使用ssh。

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

5. 

6. 

 7.

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

def remoteConfig = [:]
remoteConfig.name = "my-remote-server"
remoteConfig.host = "${REMOTE_HOST}"
remoteConfig.allowAnyHosts = true
// 使用 SCP 作为文件传输
remoteConfig.fileTransfer = "scp"

pipeline {
    agent any
    stages {
        stage('安装Node.js') {
            steps {
                sh 'rm -rf /usr/lib/node_modules/npm/'
                dir ('/root/.cache/downloads') {
                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'
                sh 'tar -xf node-v16.13.0-linux-x64.tar.xz -C /usr --strip-components 1'
                // 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'
                // sh 'tar -xf node-v14.18.2-linux-x64.tar.xz -C /usr --strip-components 1'
                // 更多版本:v12.22.7、v17.2.0
                }
                sh 'node -v'
            }
        }

        stage("检出") {
            steps {
                checkout([
                    $class: 'GitSCM',
                    branches: [[name: env.GIT_BUILD_REF]],
                    userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]]
                ])
            }
        }

        stage("安装依赖") {
            steps {
                sh "pnpm i"
            }
        }

        stage("编译") {
            steps {
                sh "pnpm build"
            }
        }
         stage('部署') {
            steps {
                echo '发布中...'
                    script {
                    def remote = [:]
                    remote.name = 'server2'
                    remote.allowAnyHosts = true
                    remote.host = "${REMOTE_HOST}"
                    remote.port = 22
                    remote.user = "${REMOTE_USER_NAME}"
                    withCredentials([ sshUserPrivateKey(credentialsId:"${REMOTE_CRED}"
                    ,keyFileVariable:'SSH_PRIVATE_KEY_PATH')]) {
                        remote.identityFile = SSH_PRIVATE_KEY_PATH
                        sshPut remote: remote, from: './dist/.', into: '/html/aia'
                        sshCommand remote: remote, sudo: true, command: "cp -rf /html/aia/dist/* /html/aia"
                        sshCommand remote: remote, sudo: true, command: "rm -rf /html/aia/dist"
                    }
                }

                echo '发布完成.'
            }
        }
    }
}


9.填写变量 

 10.点击立即构建即可

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值