0

I have a jenkins multibranch pipeline where I run terragrunt code, in order to clean up the output logs I would like to redirect the terragrunt destroy output to a txt file and archive it.

Locally everything works as expected, but on jenkins the txt file is empty

i have attempted:

destroy > file.txt
destroy >> file.text
destroy 2>&1 >> file.txt
destroy >> file.txt 2>&1
destroy |& sed 's/\x1b\[[0-9;]*m//g' &>> file.txt

The last one was on the recommendation from a co-worker that it might have to do with the color output.

Scope of work:

sh "touch file.txt"

locations.each {
 dir(it){
  sh 'terragrunt destroy 2>&1 >> file.txt'
 }
}

Not sure what else to try, all the other methods ive looked at seem to also still output to the console which defeats the goal of cleaning up the console output for readability.

Dom
  • 205
  • 2
  • 9

2 Answers2

0

What's the difference of strings within single or double quotes in groovy?

So this should work

sh '''
  cd LOCATION
  terragrunt destroy 2>&1 >> file.txt
'''
hakamairi
  • 4,464
  • 4
  • 30
  • 53
  • switching to single quotes didnt solve the problem it still isnt outputting to the file – Dom Jul 23 '19 at 16:06
  • You can try to write a shell script and call it from your pipeline. This way you would eliminate the possibility that something is wrong in there. Other than that jenkins executes the jobs on separate user, normally called `jenkins` - it might be worth checking if the user has all the tools and permissions. – hakamairi Jul 23 '19 at 16:12
0

So after lots of trial an error I was able to get it to work... sort of

I had to create a txt file for each destroy cmd, it looks like redirect and append doesnt work

Dom
  • 205
  • 2
  • 9