cordova-11/Jenkinsfile
2022-05-25 10:33:29 +08:00

64 lines
2.3 KiB
Groovy
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

node {
try{
stage('检出代码'){
git branch: "${BRANCH}",credentialsId: 'taolin', url: "${REPO_URL}"
sh 'ls'
sh 'pwd'
echo "Gradle $GRADLE_HOME"
echo "Java $JAVA_HOME"
}
stage("替换图标") {
sh 'wget -o logo.png ${APPLOGO}'
}
stage('修改配置文件'){
//获取content所在行 CONTENT_URL
def num = getShEchoResult ("sed -n '/content/=' config.xml")
sh "sed -i '${num}d' config.xml"
sh "sed -i '${num}i<content src=\"${CONTENT_URL}\" />' config.xml"
//APP_NAME
sh "sed -i 's/<name>.*<\\/name>/<name>${APP_NAME}<\\/name>/g' config.xml"
//APP_ID APP_VERSION
def verNum = getShEchoResult ("sed -n '/<widget/=' config.xml")
sh "sed -i '${verNum}d' config.xml"
sh "sed -i '${verNum}i<widget id=\"${APP_ID}\" version=\"${APP_VERSION}\" xmlns=\"http://www.w3.org/ns/widgets\" xmlns:cdv=\"http://cordova.apache.org/ns/1.0\">' config.xml"
sh "cat config.xml"
}
stage('编译'){
try{
sh 'npm install'
sh 'npm run initial'
sh 'npm run logo'
sh "npx cordova build android"
}catch(e){
}
}
stage('存档'){
echo "参数 ${EMAIL}"
def apk = getShEchoResult ("find ./platforms/android/app/build/outputs/apk/debug -name '*.apk'")
echo "APK ${apk}"
def artifactsDir="artifacts"//存放产物的文件夹
sh "mkdir ${artifactsDir}"
sh "mv ${apk} ${artifactsDir}"
sh 'ls artifacts'
archiveArtifacts "${artifactsDir}/*"
}
stage('通知负责人'){
emailext(body: "构建项目:${BUILD_URL}\r\n构建完成",mimeType: "text/html",subject: '构建结果通知【成功】',to: "${EMAIL}",attachmentsPattern: "artifacts/app-debug.apk")
}
} catch (e) {
emailext( body: "构建项目:${BUILD_URL}\r\n构建失败\r\n错误消息${e.toString()}", subject: '构建结果通知【失败】', to: "${EMAIL}")
} finally{
// 清空工作空间
cleanWs notFailBuild: true
}
}
// 获取 shell 命令输出内容
def getShEchoResult(cmd) {
def getShEchoResultCmd = "ECHO_RESULT=`${cmd}`\necho \${ECHO_RESULT}"
return sh (
script: getShEchoResultCmd,
returnStdout: true
).trim()
}