4

I'm using Terraform as part of a Jenkins Pipeline. When terraform apply encounters an error, it does not return a non-zero exit code. When running into a problem on Jenkins, it does not stop the pipeline or mark the build as FAILURE.

If terraform encounters an error, I need the job to stop and not progress.

Looking at the docs for apply, it doesn't look like I can provide a flag to return helpful exit codes. The docs for plan has a -detailed-exitcode flag, but doesn't look like that'll help me.

closed as off-topic by Richard Slater, Pierre.Vriens, Dan Cornilescu, Aurora0001, Tensibai Apr 13 '17 at 9:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Richard Slater, Pierre.Vriens, Dan Cornilescu, Aurora0001, Tensibai
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Would sidestepping the issue by running terraform apply | tee /dev/tty | ( ! grep "Error applying plan" ) work? That will return 1 if the "Error applying plan" text is in the output. Let me know if that's a suitable answer for you, or if you're looking for a more graceful solution. – Aurora0001 Apr 12 '17 at 19:47
  • Thanks for your response. That would do the job, but it's a little more of a hack than what I was hoping for. – Dan Mandle Apr 12 '17 at 19:54
3

Turns out this was not a real issue. My apologies. At the end of that shell script, it did an echo which is what was returning the non-zero status code. After I took that out, it worked as expected.

  • shouldn't jenkins fail is any command in 'execute shell' returns non-zero? – xddsg Nov 23 '17 at 14:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.