Use Coding to automate the deployment of vue projects (useful for pro-testing) Coding deploys vue projects

Article directory

Use Coding to automate the deployment of vue projects (useful for pro-testing)

Login to coding official website

1. Create a new project. See the text below. The new vue project is the same as java

select this new

insert image description here

Select the code repository and click OK

insert image description here

Choose a text editor

insert image description here

Paste the following content in, and then change a few content servers and credential ids

pipeline {
    
    
  agent any
  stages {
    
    
    stage('检出') {
    
    
      steps {
    
    
        checkout([$class: 'GitSCM',
        branches: [[name: env.GIT_BUILD_REF]],
        userRemoteConfigs: [[
          url: env.GIT_REPO_URL,
          credentialsId: env.CREDENTIALS_ID
        ]]])
      }
    }
    stage('安装构建') {
    
    
          stage('编译') {
    
    
      steps {
    
    
        sh 'yarn install'
      }
    }
    stage('构建') {
    
    
      steps {
    
    
        sh 'yarn build'
      }
    }
    stage('部署') {
    
    
      steps {
    
    
        echo '发布中...'
        script {
    
    
          def remote = [:]
          remote.name = 'server2'
          remote.allowAnyHosts = true
          remote.host = '服务器ip'
          remote.port = 22
          remote.user = 'root'
          withCredentials([ sshUserPrivateKey(credentialsId:'凭据 ID',keyFileVariable:'SSH_PRIVATE_KEY_PATH')]) {
    
    
            remote.identityFile = SSH_PRIVATE_KEY_PATH

            sshPut remote: remote, from: './dist/.', into: '/root/erp/web'
            sshCommand remote: remote, sudo: true, command: "cp -rf /root/erp/web/dist/* /root/erp/web/"
            sshCommand remote: remote, sudo: true, command: "rm -rf /root/erp/web/dist"
          }
        }

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

Modified content server ip

This ./dist/. is the packaged path of yarn install. This is the server file path. Ensure that there is a folder /root/erp/web/ with permissions.

Modify the credential id acquisition method as follows

insert image description here

The SSH private key* acquisition method is demonstrated here for the pagoda server, and the others are similar

Enter ssh-keygen -m PEM -t rsa in the Pagoda terminal and press Enter

insert image description here

SSH private key* Put this SSH private key* in this file and save it here

/root/.ssh/id_rsa.

insert image description here

There is also the ssh public key to configure the public key in the pagoda in this file

/root/.ssh/id_rsa.pub.

Copy the content of the generated public key (id_rsa.pub.) and put it into (accessed) server root/.ssh/authorized_keys Paste it into this file to indicate authorization; other servers can access this server through the private key without this file or folder to create one;

insert image description here

It is recommended to directly authorize here and click to confirm

insert image description here

After creation, copy this credential id and save it for use below

Finally, click Save and click Build Now, then you can upload the dist file to the specified address on the server

In the future, just click build every time or set it to push code to build

Note that the vue project needs to be started for the first time, and then you don’t need to start it, just click build, vue’s first start method

see the following article

click to jump

Guess you like

Origin blog.csdn.net/weixin_48616345/article/details/132515543