I am writing multiple lines in a variable to a file as part of my build step in groovy jenkins.
def output = GetProfiles()
String[] rev = output.toString().split("\n");
for(int i=0;i<rev.length;i ) {
String cred = rev[i]
bat "@echo off && echo $cred >> \"$tmpDir\\credentials\""
}
GetProfiles returns multiple lines of data and the above code works. However, it takes alot of time as it writes to the file line by line.
Is there a better approach to writing the entire set of lines in the variable to a file in one go? I tried encasing the echo command in ()
but that doesn't work.
bat "@echo off && (echo $output) > \"$tmpDir\\credentials\""
CodePudding user response:
def output = GetProfiles().toString()
writeFile( file: "$tmpDir/credentials", text: output )