[英]Convert a JSON style String to a map Groovy in Jenkinsfile
我有一個看起來像這樣的字符串{"analyzer": "static_analyzer", "status": "success", "hash": "3c8f0dae82136f0a1447de5531e5bd03", "scan_type": "zip", "file_name": "jenkins-iOS-BuildVerify-GH-PR-6487-38.zip"}
。 我想解析它並獲取“hash”的值,但我找不到任何現有的方法來將它轉換為地圖。
我假設您正在使用 Jenkins 管道。 如果是這樣,您可以執行以下操作。 這里我使用內置的readJSON
選項。 你可以在這里閱讀更多。
pipeline {
agent any
stages {
stage('Sample') {
steps {
script {
def jsonString = '{"analyzer": "static_analyzer", "status": "success", "hash": "3c8f0dae82136f0a1447de5531e5bd03", "scan_type": "zip", "file_name": "jenkins-iOS-BuildVerify-GH-PR-6487-38.zip"}'
def props = readJSON text: jsonString
def hash = props['hash']
echo "$hash"
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.