pipeline { agent any tools { nodejs 'node14' } parameters { choice name: 'branch', description: '选择分支', choices: ['dev','master'] } stages { stage('Checkout') { when { not { environment name: 'branch', value: '' } } steps { git branch: "zjsu-mall-h5", credentialsId: 'id_rsa_example', url: 'git@example.com:daqianduan/uniapp-cli-base.git' dir('src') { git branch: "${env.branch}", credentialsId: 'id_rsa_example', url: 'git@example.com:daqianduan/gongshang-mall-h5.git' } } } stage('Compile') { when { not { environment name: 'branch', value: '' } } steps { sh ''' npm set registry https://registry.npmmirror.com/ npm set disturl https://npmmirror.com/mirrors/node npm set sass_binary_site https://registry.npmmirror.com/-/binary/node-sass npm set chromedriver_cdnurl https://registry.npmmirror.com/-/binary/chromedriver ''' // sh 'npm install -g cnpm' sh 'npm install' // sh 'npm rebuild node-sass' sh 'npm install uview-ui@2' sh 'npm install pug@2' sh 'npm install pug-plain-loader' sh 'npm install jweixin-module@1.6.0' sh 'npm install clipboard dayjs' //sh 'npm run build:h5' sh 'npm run build:custom h5-dev' sh 'test -d dist/build && tar -zcvf h5.tar.gz --directory=dist/build/ h5' } } stage('Deploy') { when { not { environment name: 'branch', value: '' } } steps { script { def dt = new Date().format('yyyy-MMdd-HHmmss') def remoteDir = '/home/projects/zjsu-mall/h5-ui' //def remotePkg = "${remoteDir}/h5-${dt}.tar.gz" def remotePkg = "${remoteDir}/h5.tar.gz" withCredentials([sshUserPrivateKey(credentialsId: 'id_rsa_example', keyFileVariable: 'identity')]) { def remote = [name: '11.22.33.44', host: '11.22.33.44', user: 'root', port: 2222, allowAnyHosts: true, identityFile: identity] sshPut remote: remote, from: 'h5.tar.gz', into: remotePkg sshCommand remote: remote, command: """ rm -fr ${remoteDir}/h5 tar -xzf ${remotePkg} -C ${remoteDir} """ } } } } } }