簡體   English   中英

Jenkins Echo 響應(Http 狀態和正文)

[英]Jenkins Echo Response(Http status and Body)

收到script.sh: 1: Syntax error: "(" unexpected在具有def http_status的行上script.sh: 1: Syntax error: "(" unexpected 。可能是什么問題?

   stage('alert') {
    withCredentials([string(credentialsId: 'org_user_key', variable: 'userKey'), string(credentialsId: 'org_api_key', variable: 'apiKey')]) {
        def response = sh(script: "curl -X POST \
                                --header 'Content-Type: application/json' \
                                --data '{\"requestType\" : \"getProductAlerts\",\"productToken\" : \"${productToken}\", \"userKey\" : \"${userKey}\"}' \
                                 'https://saas-eu.whitesourcesoftware.com/api/v1.3'", returnStdout: true).trim()

        def http_status = sh(script: "echo \"${response}\" | grep HTTP |  awk '{print \$2}", returnStdout: true)
        sh "echo  \"${http_status}\""
        def body = sh(script: "echo \"${response}\" | grep body", returnStdout: true)
        sh "echo  \"${body}\""
    }
}

我認為您在 awk 命令后缺少單引號:

def http_status = sh(script: "echo \"${response}\" | grep HTTP |  awk '{print \$2}", returnStdout: true)

相對

def http_status = sh(script: "echo \"${response}\" | grep HTTP |  awk '{print \$2}'", returnStdout: true)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM