Jenkins Pipeline非timeout模式获取sonarqube扫描值

需要插件Pipeline Utility Steps、 HTTP Request Plugin

pipeline {
    agent {
        label 'slave-linux-1'
    }
    stages {
        stage("客户端代码静态检查") {
            steps {
                echo "*****************START CODE CHECK*****************"
                script {
                    def map = ["android":"prdandroid"]
                    map.each {
                        withSonarQubeEnv(credentialsId: 'sonar-login',installationName: 'SonarQubeServer') {
                            echo it.key
                            // 执行sonarqube扫描,安卓项目,使用的是gradle,java项目可换成mvn
                            // sh "./gradlew clean"
                            // sh "./gradlew sonarqube -x test"
                        }
                        timeout(time:3,unit:'MINUTES'){
                            waitUntil{
                                script {
                                    // report-task.txt 这个文件的路径是固定的,扫描一次以后去服务器上找到放在这即可
                                    def ceTaskUrl = sh label: '', returnStdout: true, script: 'awk -F \'l=\' \'/ceTaskUrl/{print $NF}\' build/sonar/report-task.txt'
                                    // 发送请求获取json串,这部分要把登录信息带过去,我在浏览器上输入账号密码后取的Cookie
                                    def responseTask = httpRequest contentType: 'APPLICATION_JSON',
                                        httpMode: "GET",
                                        customHeaders: [
                                            [name: "Cookie", value: "XSRF-TOKEN=bbdbddgcdsld0sgv8a1jf5062g; JWT-SESSION=eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJBWE9mekdRTkxibWQybFA4cGc3ZyIsInN1YiI6ImFkbWluIiwiaWF0IjoxNTk2MTEzODM5LCJleHAiOjE1OTYzNzMwMzksImxhc3RSZWZyZXNoVGltZSI6MTU5NjExMzgzOTExNywieHNyZlRva2VuIjoiYmJkYmRkZ2Nkc2xkMHNndjhhMWpmNTA2MmcifQ.D_IPV9C2O_tol9MrkLFOiO_wM9uaEelcZLPCV9S6tuc"]
                                        ],
                                        url: ceTaskUrl
                                    
                                    // 读取json串
                                    ceTask = readJSON(text:responseTask.content)
                                    // println(ceTask)
                                    // 当json中的status的值为SUCCESS时,值为真,退出waitUntil,如果timeout时间内一直不为真(扫描状态为ERROR或正在扫描),则报错退出
                                    return "SUCCESS".equals(ceTask["task"]["status"])   
                                }
                            }
                        }
                    }
                }
                echo "*****************CODE CHECK DONE*****************"
            }
        }
    }
}

整的太复杂了 :blush: