Jenkins中的groovy字符串比较


Groovy版本$groovy--版本Groovy版本:2.4.7 JVM:1.8.0_91供应商:Oracle Corporation操作系统:Mac OS X

以下代码适用于我的mac

import groovy.json.JsonSlurper
def StackStatusJson="aws  cloudformation describe-stacks --stack-name XXXXXX".execute().text
println(StackStatusJson)
try{
def jsonSlurper = new JsonSlurper()
def object=jsonSlurper.parseText(StackStatusJson)
println("StackStatus->"+object.Stacks.StackStatus)
String v=object.Stacks.StackStatus
if(v.equals("[CREATE_COMPLETE]"))
{
    println("Calling Deploy Artifacts")
    deployArtifacts()
}
}catch(err)
{
    println(err);
}
def deployArtifacts()
{
    println "I am called"
}

但在Jenkins v 2.15管道上,下面的字符串比较失败。我不明白为什么它没有使条件成为真正的

if(v.equals("[CREATE_COMPLETE]"))
   {
    println("Calling Deploy Artifacts")
    deployArtifacts()
   }
}catch(err)
{
    println(err);
}    

用于测试的示例JSON低于值Stubbed

{
    "Stacks": [
        {
            "StackId": "XXXXX", 
            "Description": "XXXXXX Environment", 
            "Parameters": [
                {
                    "ParameterValue": "XXXXXXX", 
                    "ParameterKey": "proxy"
                }, 
                {
                    "ParameterValue": "XXXXXX", 
                    "ParameterKey": "amiid"
                }, 
                {
                    "ParameterValue": "XXXXXX", 
                    "ParameterKey": "TopicARN"
                }, 
                {
                    "ParameterValue": "XXXXXX", 
                    "ParameterKey": "yumproxy"
                }, 
                {
                    "ParameterValue": "m3.large", 
                    "ParameterKey": "InstanceType"
                }
            ], 
            "Tags": [], 
            "CreationTime": "2016-08-28T06:34:12.324Z", 
            "StackName": "XXXXXX", 
            "NotificationARNs": [], 
            "StackStatus": "CREATE_COMPLETE", 
            "DisableRollback": false
        }
    ]
}

代码行

String v=object.Stacks.StackStatus

应读取

String v = object.Stacks[0].StackStatus

因为CCD_ 1是阵列。

相关内容

  • 没有找到相关文章

最新更新