运维开发网

Jenkins 安卓打包在描述处显示二维码

运维开发网 https://www.qedev.com 2020-10-17 12:17 出处:51CTO 作者:rong341233
pipeline{agent{label'Linux'}parameters{gitParameterbranch:'',branchFilter:'.*',defaultValue:'origin/master',description:'代码分支',name:'project',quickFilterEnabled:false,selectedValue:'NONE',sortMode:'NO
pipeline {
    agent {
        label 'Linux'
    }
    parameters {
        gitParameter branch: '', branchFilter: '.*', defaultValue: 'origin/master', description: '代码分支', name: 'project', quickFilterEnabled: false, selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '*', type: 'PT_BRANCH_TAG'
    }

    stages {
        stage('Checkout Code') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '${project}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxxxxxxxxxxxxxxxxxxxxx', url: 'ssh://[email protected]/xxxx/xxxx.git']]])
            }
        }
        stage('构建APK'){
            steps {
                sh label: '', script: '''
                /usr/local/gradle-5.1.1/bin/gradle assembleRelease
                '''
            }
        }
        stage('上传APK'){
            steps {
                sh label: '', script: '''
                cd app/build/outputs/apk/release
                cp -rf *.apk  app-release.apk
                qrcode=$(curl -s -k -F "[email protected]" http://app.t.isjue.cn/upload.php)
                echo ${qrcode}>qrcode
                '''
                script {
                    QRCODE = sh(returnStdout: true, script: 'cd app/build/outputs/apk/release && cat qrcode')
                    VERSION = sh(returnStdout: true, script: "echo $project")
                    buildDescription  "构建分支:${VERSION}<br><img src=${QRCODE}></img>"
                }    
            }
        }
    }

    post {
        always {
            echo 'One way or another, I have finished'
            deleteDir() /* clean up our workspace */
        }
        success {
            // buildDescription("<img src=${qrcode}></img>")
            echo 'I succeeeded!'
        }
        unstable {
            echo 'I am unstable :/'
        }
        failure {
            echo 'I failed :('
        }
        changed {
            echo 'Things were different before...'
        }
    }
}

重点就是这句:

通过shell返回的结算,赋值为变量

script {

QRCODE = sh(returnStdout: true, script: 'cd app/build/outputs/apk/release && cat qrcode')

VERSION = sh(returnStdout: true, script: "echo $project")

buildDescription "构建分支:${VERSION}<br><img src=${QRCODE}></img>"

}

然后设置为描述信息

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号