coding 自动集成指定node版本

注意

下面的脚本在coding中使用时删除注释。不然无法通过检测

coding配置

指定node版本为 14.18.2

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 '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=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'
        }
        sh 'node -v'
        sh 'npm -v'
        sh 'npm install'
        sh 'npm run build:dev'// 打包
        sh 'rm -f /root/workspace/dist.tar.gz'
        sh 'tar -zcf /root/workspace/dist.tar.gz dist/'
      }
    }
    stage('部署') {
      steps {
        pwd(tmp: true)
        script {
          def remoteConfig = [:]
          remoteConfig.name = "服务器名称"
          remoteConfig.host = "服务器ip"
          remoteConfig.port = "22".toInteger() //端口
          remoteConfig.allowAnyHosts = true

          withCredentials([usernamePassword(credentialsId: "服务器配置", usernameVariable: '账号id', passwordVariable: '密码id')]) {
            remoteConfig.user = username
            remoteConfig.password = password

            //上传dist压缩包 压缩文件上传到服务器
            sshPut remote: remoteConfig, from: '/root/workspace/dist.tar.gz', into: '/home/hhhh/'
            //删除原dist
            sshCommand(remote: remoteConfig, command: 'rm -rf /home/hhhh/dist')
            //解压文件
            sshCommand(remote: remoteConfig, command: 'tar zxvf  /home/hhhh/dist.tar.gz -C /home/hhhh/')
          }
        }
      }
    }
  }
}

其他node版本

  • v14.16.0稳定版地址:https://npm.taobao.org/mirrors/node/v14.16.0/node-v14.16.0-linux-x64.tar.xz
  • https://nodejs.org/download/rc/
  • https://nodejs.org/dist/v16.19.1/
  • https://nodejs.org/dist/v16.19.1/node-v16.19.1-linux-x64.tar.xz
    想要对应版本的去https://nodejs.org/dist/中找一下。
    注意下载后缀为.tar.xz的就行

你可能感兴趣的:(coding,指定node版本)