2
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
  • 244,070
  • 43
  • 506
  • 972
Sidd
  • 21
  • 1
  • 2

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
  • 1,014
  • 5
  • 12