我正在嘗試將 Jenkins 管道用于 Json 格式輸入。我正在嘗試在多行字串引數中傳遞 Json 格式字串,我正在傳遞如下圖所示的引數,但我無法使用 JsonSlurper 決議它,其中 test 是多行字串輸入的名稱。誰能幫助我如何在 groovy 中決議它?
是否可以在多行字串引數中決議 Json 格式?
多行字串引數輸入為 Json
def jsonSlurper = new JsonSlurper();
def infra = jsonSlurper.parse($test) ;
uj5u.com熱心網友回復:
您不必為此使用 JsonSulper,您可以改用readJson步驟。這是一個完整的示例。
pipeline {
agent any
parameters { string(name: 'JSON', defaultValue: 'staging', description: '') }
stages {
stage ("Example") {
steps {
script{
def jsonObj = readJSON text: "${params.JSON}"
echo "$jsonObj"
} }
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/508718.html
