Deepanshu Kalra
Deepanshu Kalra

Reputation: 479

Writing multiline variable to file cmd

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\""

Upvotes: 0

Views: 2150

Answers (1)

daggett
daggett

Reputation: 28634

def output = GetProfiles().toString()
writeFile( file: "$tmpDir/credentials", text: output )

Upvotes: 1

Related Questions