如果 json 结果包含错误,如何在 groovy 脚本中执行另一个任务 - “ErrorSeverity”:“Error”

问题描述 投票:0回答:0

我需要从 Jenkins Job(通过 PowerShell 执行)获取 JSON 格式的代码审查报告。然后我保存这个 json 报告有环境变量。然后,从 Jenkins 中,使用 Groovy Postbuild 操作发送一封带有附加 json 的电子邮件。

现在我需要阅读 json 并搜索 **"ErrorSeverity": "Error" **,然后再发出另一个请求以使用 JIRA API 打开 JIRA 票证。

关于如何读取 json 文件以检索 ErrorSeverity,然后在 ErrorSeverity 出错时触发 JIRA API 的任何想法?

JSON 输出示例:

#json{ "FilePath": "E:\\packages\\workspace\\Dummy_Repo_PR-53\\Calculator\\Calculator_EnterInputData.xaml", "ErrorCode": "ST-NMG-004", "ErrorSeverity": "Warning", "Description": "Log Message display name is defined many times. Current allowed threshold is 1. Code contains 2.", "Recommendation": "Names of activities should give a clear indication of how they are being used. Default names are usually too generic. Please avoid duplicate names. [Learn more.]", "FilePath": "E:\\packages\\workspace\\Dummy_Repo_PR-53\\Calculator\\Calculator_EnterInputData.xaml", "ErrorCode": "ST-NMG-004", "ErrorSeverity": "Info", "Description": "Assign_CalculationType_ExactName display name is defined many times. Current allowed threshold is 1. Code contains 4.", "Recommendation": "Names of activities should give a clear indication of how they are being used. Default names are usually too generic. Please avoid duplicate names. [Learn more.]", "FilePath": "E:\\packages\\workspace\\Dummy_Repo_PR-53\\Calculator\\Calculator_EnterInputData.xaml", "ErrorCode": "CU-NMG-007", "ErrorSeverity": "Error", "Description": "Assign_CalculationType_ExactName display name is defined many times. Code contains 4", "Recommendation": "Activity should have a unique descriptive name  [Learn more.]", "FilePath": "E:\\packages\\workspace\\Dummy_Repo_PR-53\\Calculator\\Calculator_EnterInputData.xaml", "ErrorCode": "CU-NMG-001", "ErrorSeverity": "Info", "Description": "ActivityName Attach Window_Calculator doesn't follow the standard guidelines", "Recommendation": "Rename the activity with the standard guidelines" }#json

试图从 json 中 grep“ErrorSeverity”:“错误”,所以我没有成功。

jenkins-groovy groovyshell
© www.soinside.com 2019 - 2024. All rights reserved.