8

Is there a way fail my entire pipeline if the user triggered the pipeline and didn't set a variable called options with a value?

I've tried things like only and rules but they just skip the job instead of failing all jobs.

Doctor Who
  • 1,287
  • 5
  • 25
  • 46

1 Answers1

6

Yes, though the way you fail would be dependent on the system your runner's based on.

For example, in a Linux/bash based runner, all you need is exit 1 (as opposed to exit 0) to stop execution and fail the pipeline

mochsner
  • 307
  • 2
  • 10
  • Thanks I've given it a try but I can't get the pipeline to exit am I doing something wrong with this if in my script section? `script: - if [$options == null]; then exit 1; fi` The next line echos out options so I can see it's null but the if didn't exit – Doctor Who Jul 07 '20 at 10:36
  • 3
    $options doesn't have default value if not set? you should use it in if condition instead of null – MoonHorse Jul 07 '20 at 18:44
  • 3
    Yep, MoonHorse hit the nail on the head here. Just do use `if [ -z $options];` to make it a condition that checks if it's either unset, or null. This StackOverflow [Question](https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash) has a good summary of the different sorts of checks you could use here, but the approach above looks to be the best bet if you're looking to catch cases where the variable is unset or null. – mochsner Jul 07 '20 at 23:58