0
def NAMESPACE = "Dev"

def BODY= sh(
script:'''body=$(cat <<-EOF
{
    "name": "${NAMESPACE}",
    "type": "regularwebapp"
}
EOF
)
(echo $body)''',
returnStdout: true
).trim()

The above doesnt work, output is as follows:

{
    "name": "",
    "type": "regularwebapp"
}
Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Sidd
  • 1
  • 1
  • 1

1 Answers1

0

Groovy doesn't perform variable substitution inside single-quoted (') strings. Use double-quoted (") strings instead - this will also require escaping non-Groovy variables:

def NAMESPACE = "Dev"

def BODY= sh(
script:"""body=\$(cat <<-EOF
{
    "name": "${NAMESPACE}",
    "type": "regularwebapp"
}
EOF
)
(echo \$body)""",
returnStdout: true
).trim()
jayhendren
  • 917
  • 4
  • 11