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,这会替换掉所有被复制文件的原始名称
               )])
                }
            }
        }
    }
}
相关推荐
lpfasd1231 小时前
第2部分:Netty核心架构与原理解析
运维·服务器·架构
小蜜蜂爱编程1 小时前
gerrit的部署与配置关联到不同服务器上的git仓库
运维·服务器·git·gerrit
心灵宝贝2 小时前
申威(sw_64)架构下如何安装java-1.8.0-swjdk的rpm包?
linux·运维·服务器
半梦半醒*3 小时前
搭建Jenkins
linux·运维·centos·tomcat·jenkins·运维开发
Wang's Blog3 小时前
Linux小课堂: 系统监控与进程管理之深入解析 w、ps 与 top 命令
linux·运维·服务器
安卓开发者4 小时前
Docker常用镜像使用指南:从入门到实战
运维·docker·容器
Lenyiin5 小时前
《 Linux 点滴漫谈: 三 》掌控终端:让 Shell 成为你的系统魔杖
linux·运维·服务器·lenyiin
杭州泽沃电子科技有限公司5 小时前
钢铁厂运输设备在线监测:构建智能工厂的安全与效率基石
运维·人工智能·智能监测
Lynnxiaowen5 小时前
今天我们学习python编程常用模块与面向对象
运维·python·学习·云计算
一匹电信狗5 小时前
【MySQL】数据库表的操作
linux·运维·服务器·数据库·mysql·ubuntu·小程序