Groovy 字符串插值未正确传递

Groovy String interpolation not being passed correctly

我正在尝试 运行 使用 sh 在 Jenkins 中执行命令。这是我的工作:

ecsOracleClusterName = "foo"
ecsServiceName = sh(returnStdout: true, script: 'aws ecs list-services --cluster "${ecsOracleClusterName}" --region us-east-1').trim()

我注意到 ecsOracleClusterName 是空白的。不知道为什么会这样,但在 Jenkins 中,我收到此错误消息:

+ aws ecs list-services --cluster  --region us-east-1

An error occurred (ClusterNotFoundException) when calling the ListServices operation: Cluster not found.

如您所见,集群名称变量未传递值。这让我相信字符串插值存在问题(或者至少我是如何实现它的)。有人可以告诉我这里发生了什么吗?

尝试像这样使用双引号..

ecsOracleClusterName = "foo"
ecsServiceName = sh(returnStdout: true, script: "aws ecs list-services --cluster $ecsOracleClusterName --region us-east-1").trim()
println "Service name: ${ecsServiceName}"