bash - Jenkins Echo 响应(Http 状态和正文)
问题描述
接收错误,script.sh: 1: Syntax error: "(" unexpected
就行了def http_status
。可能是什么问题?
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)
推荐阅读
- javascript - 使用 POST 保存到服务器时如何命名音频文件
- javascript - 有没有办法在网站之外执行“提交”功能?
- ios - Firestore 数据库中的数据未显示在 tableview 中
- list - 具有最大值的列表名称
- android - '未来
' 在 Flutter 中尝试访问 Future SmsMessage 变量的主体时,没有实例 getter 'body' 错误 - sql-server - 在 SQL Server 中使用 XML 数据插入表时出错
- python - 如何在熊猫中减去两个相同的数据帧
- java - 人脸检测和使用边界框提取人脸并创建新位图
- r - 如何在非常大的数据集中找到异常值变量?
- android - 我在测试我的 android 应用程序时遇到问题,该应用程序在我的设备上运行良好,但在 MI 手机上崩溃