Jenkinsfile
pipeline {
agent any
tools {nodejs "Node14.21.2"}
stages {
stage("Git代码"){
steps{
git (branch: 'master', url: 'https://github.com/bigScreen.git', credentialsId: '7eb7e4ee-002f-4af7-9048-72c76b5a94da')
}
}
stage("配置Env"){
steps{
script{
env.DATE = new Date().format('yyyy-MM-dd HH:mm:ss')
env.commit = "${sh(script:'git log --oneline --no-merges|head -1', returnStdout: true)}"
env.branch= "${sh(script:'git branch --show-current', returnStdout: true)}"
}
}
}
stage("Vue打包"){
steps{
sh """
node -v
npm config set unsafe-perm=true
npm config set registry https://registry.npmmirror.com
npm install --ignore-scripts
npm run build
cd dist/
tar -zcvf dist.tar.gz *
"""
}
}
stage("部署代码"){
steps{
sshPublisher(publishers: [sshPublisherDesc(configName: 'XPLSM-192.168.110.5', transfers: [sshTransfer(cleanRemote: false, excludes: '',
execCommand: '''cd /dataA/www/vnet/ \\
&& tar -zxvf dist.tar.gz && rm -f dist.tar.gz''', execTimeout: 620000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+',
remoteDirectory: '/dataA/www/vnet/', remoteDirectorySDF: false, removePrefix: 'dist/', sourceFiles: 'dist/dist.tar.gz')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
stage("钉钉通知"){
steps{
sh """curl 'https://oapi.dingtalk.com/robot/send?access_token=xxxxx' -H 'Content-Type: application/json' -d '{"msgtype":"text","text":{"content": "部署成功通知\n部署服务:${env.JOB_NAME} \n构建分支: ${env.branch} \n构建ID: ${env.BUILD_ID}\n提交信息:${env.commit}\n部署时间:${new Date().format('yyyy-MM-dd HH:mm:ss')}\n构建状态:${currentBuild.currentResult}"}}'"""
}
}
}
}