jenkins pipeline

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                echo 'Hello World  111'
                echo  env.JOB_NAME
               //  println   "name: " + getName()
                
            }
        }
        
          stage('Git Checkout') {
            steps {
                git credentialsId: 'git' , branch: env.JOB_NAME,   url:  '[email protected]:src0711.git'
            }
        }
        
         stage('Get Last Commit') {
            steps {
                script {
                
                    // 获取最后一次提交日志
                    def lastCommit = sh(returnStdout: true, script: "git log -n 1 --pretty=%B")
                    echo "最后一次提交的日志为: $lastCommit"
                   
                }
                
               
            }
        }
        
      
        
        stage('Build APK') {
            steps {
                 // def currentDir = pwd()
                // 切换到新的目录
                dir(pwd() + '/u05/5mic/v2/OneApp') {
                    
                    
                      script {
                    def jobName = env.JOB_NAME
                    echo "当前任务名称:$jobName"
                    
                      // 在新目录下执行操作
                   //  echo 'Hello World  2222'
                    sh 'chmod 777 gradlew'
                    sh "./gradlew clean build -PbranchName=$jobName"
                      sh  "./gradlew copyApk -PbranchName=$jobName"
                    // ...
                    
                }
                    
                  
                    
              
                    
                }
            }
        }
        
        
        
        
    }
}

你可能感兴趣的:(linux,jenkins,运维)