vue 前端项目每次 RD 编译差不多 1 分钟,导致时间浪费。当前编译的版本修复了哪些功能还要通知 QA;
能否通过 jenkins 解决此问题?
jenkins2.0 开始,提供了 pipeline 模式。个人认为 pipeline 模式的优点:
currentBuild.changeSets 变量中存储了 git 的 commit 的信息,通过解析该参数能获取到每次 commit 的用户以及 commit 信息;具体可查看代码中的 getChangeString 函数(此段代码 copy 自网络)
脚本主要内容:
npm install 后,不要使用 cnpm build
npm install/build ,失败,此时该命令执行仍然是成功的,可对 install、build 日志进行判断当前步骤是否失败;
node {
stage('GitCheckout'){
script{
checkout([$class: 'GitSCM', branches: [[name: '*/developer']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'demo.jin', url: 'http://git.demo.com/qa_dev/demo.git']]])
}
}
stage('Build') {
script{
def installStatus = sh (returnStatus: true, script: 'cnpm install || exit 1')
sh 'cnpm rebuild node-sass'
if(installStatus !=0){
echo 'npm install 异常,请检查日志'
sendEmail("构建npm install失败")
sh 'exit 1'
}
def buildLog = sh (returnStdout: true, script: 'cnpm run build || echo "ERROR"')
echo 'build fineshed '+buildLog
if(buildLog.contains('ERROR')){
echo 'npm build异常,请检查日志'
sendEmail("构建npm build失败")
sh 'exit 1'
}
}
}
stage('Deploy') {
script{
def scpStatus = sh (returnStatus: true, script: 'scp -r -P 22 ./dist/* root@192.168.231.100:/home/work/matrix-web ')
if(scpStatus != 0){
echo 'scp 失败'
sendEmail("构建scp失败")
sh 'exit 1'
}
sendEmail("部署成功")
}
}
}
@NonCPS
def getChangeString() {
MAX_MSG_LEN = 100
def changeString = ""
def sendMail="liukang.deme@demo.com,demo.jin@demo.com,"
echo "Gathering SCM changes"
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
sendMail = sendMail+"${entry.author}@demo.com,"
changeString += "--${truncated_msg} [${entry.author}]\n"
}
}
if (!changeString) {
changeString = " - 无"
}
return [sendMail,changeString]
}
def sendEmail(status) {
def sendObject = getChangeString()
echo "${sendObject[0]}"
echo "${sendObject[1]}"
emailext attachLog: true, body: "更新记录:\n " + "${sendObject[1]}" + "\n\n 构建日志: $BUILD_URL/console" + "\n",
subject: "${JOB_NAME} (${BUILD_NUMBER})-"+status,to: "${sendObject[0]}"
}