pipeline {
agent any
stages {
stage('Git Checkout') {
steps {
script {
def a = env.JOB_NAME
def splittedStrings = a.split('_')
echo splittedStrings[splittedStrings.size()-1]
env.app = splittedStrings[splittedStrings.size()-1]
def branch = splittedStrings[0..splittedStrings.size()-2].join("_")
echo "当前分支名称:$branch"
env.branch = branch
git credentialsId: 'git' , branch: branch, url: 'git@192.168.1.253:src0711.git'
}
}
}
stage('Get Last Commit') {
steps {
script {
// 获取最后一次提交日志
def lastCommit = sh(returnStdout: true, script: "git log --format=\"%cn %s\" -n 1")
env.lastCommit = lastCommit.trim()
echo "最后一次提交的日志为: ${env.lastCommit}"
}
}
}
stage('Build APK') {
steps {
// def currentDir = pwd()
// 切换到新的目录
dir(pwd() + "/u05/5mic/v2/${env.app}") {
script {
echo "当前分支名称:${env.branch}"
sh 'chmod 777 gradlew'
sh "./gradlew clean assemblerelease -PbranchName=${env.branch} -Plast_commit='${env.lastCommit}'"
}
}
}
}
stage('Copy APK') {
steps {
// 切换到新的目录
dir(pwd() + '/u05/5mic/v2/${env.app}/app/build/outputs/apk') {
fileOperations([fileCopyOperation(
excludes: '',
flattenFiles: true,
includes: '**/*.apk',
renameFiles: true, // 启用文件重命名功能
sourceCaptureExpression: '',
targetLocation: "/home/a/Desktop/a123/${env.branch}",
targetNameExpression: '${env.apk}.apk' // 设置目标文件名为 a.apk,这会替换掉所有被复制文件的原始名称
)])
}
}
}
}
}
Jenkins 编译脚本
最新推荐文章于 2024-06-13 11:28:58 发布