Jenkins 编译脚本

groovy 复制代码
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,这会替换掉所有被复制文件的原始名称
               )])
                }
            }
        }
    }
}
相关推荐
HIT_Weston2 小时前
93、【Ubuntu】【Hugo】搭建私人博客:面包屑(一)
linux·运维·ubuntu
cuijiecheng20183 小时前
Linux下Beyond Compare过期
linux·运维·服务器
喵叔哟3 小时前
20.部署与运维
运维·docker·容器·.net
HIT_Weston3 小时前
92、【Ubuntu】【Hugo】搭建私人博客:侧边导航栏(六)
linux·运维·ubuntu
CodeAllen嵌入式3 小时前
Windows 11 本地安装 WSL 支持 Ubuntu 24.04 完整指南
linux·运维·ubuntu
RisunJan7 小时前
Linux命令-ipcs命令(报告进程间通信(IPC)设施状态的实用工具)
linux·运维·服务器
HABuo8 小时前
【Linux进程(四)】进程切换&环境变量深入剖析
linux·运维·服务器·c语言·c++·ubuntu·centos
橘颂TA8 小时前
【Linux】死锁四条件的底层逻辑:从锁冲突到 STL 组件的线程安全实践(Ⅵ)
linux·运维·服务器·c++·死锁
黄焖鸡能干四碗8 小时前
智能制造工业大数据应用及探索方案(PPT文件)
大数据·运维·人工智能·制造·需求分析