0

My jenkinsfile contains a really long one-line shell command to create gradle.properties. For better readability I replaced it with Heredoc. It does fail now though and I am unsure why. Can you spot the error?

One-liner that does not fail is in this format:

sh("echo -e \"\nSOME_KEY=${VARIABLE_1}\nANOTHER_KEY=${VARIABLE_2}\nYET_ANOTHER_KEY=${VARIABLE_3}\" >> gradle.properties")

Failing Heredoc format:

sh("""cat << EOF >> gradle.properties
SOME_KEY=${VARIABLE_1}
ANOTHER_KEY=${VARIABLE_2}
YET_ANOTHER_KEY=${VARIABLE_3}
EOF""")
yelinek
  • 43
  • 5
  • What's with all the indentation in your heredoc? – user2357112 Jan 23 '23 at 23:48
  • My mistake. This happened when pasting and formatting on stackoverflow. – yelinek Jan 24 '23 at 00:03
  • @yelinek Is your multiline string correct? I'm not familiar with multiline strings in Jenkinsfiles specifically, but I'm assuming that the one you put will evaluate to `"cat << EOF >> gradle.propertiesSOME_KEY=${VARIABLE_1}ANOTHER_KEY=${VARIABLE_2}YET_ANOTHER_KEY=${VARIABLE_3}EOF"`. Try putting a space at the beginning of each line of the multiline string. – Wilson Jan 24 '23 at 04:41
  • Alternatively you may need to insert EOL characters. – Wilson Jan 24 '23 at 04:43
  • @shellter tripple `"` is a multiline string in jenkinsfile – yelinek Jan 24 '23 at 09:38

0 Answers0