Search code examples
groovyjenkins-groovygroovyshellgroovy-console

I have multi lines in my code, I want to write certain lines in a new line, how can I do it in groovy body


body:"""
Hi, how are you? Yes, I am doing good. what about you. How are things going?
Nothing interesting, as usual.
"""

In the above lines, I want to print a sentence in new line in groovy (body), how can I accomplish that? Note: I am new to groovy

I tried using b tag and nothing worked.


Solution

  • You have done it correctly...

    body:"""Hi, how are you?
    Yes, I am doing good.
    what about you.
    How are things going?
    Nothing interesting, as usual."""
    

    You can also ask the system for the correct line separator, since it can change on different operating systems.

    writer << "Line 1" + System.getProperty("line.separator") + "Line 2"