0

I tried to implement the if else condition in Airflow, if a condition is true then statements under this condition will execute. In the else part the statements will not execute and return the task as failed

"a=0;" 
"if [[$a -ge "1"]] ; then"
"   echo 'Job Success';"
"else "
"   echo 'Need Investigation';"
"   exit 0;"
"fi;"

Here, If a is equal to 1 then the echo statement 'Job Success' is printed If a is equal to 0 then the echo statement is not printed and the respective Airflow Dag is marked as failed

  • Note also that `[[` isn't guaranteed to work with `/bin/sh` -- make sure airflow is _really_ using bash as its shell, or switch to `if [ "$a" -ge 1 ]; then` (escaping the quotes as appropriate -- that's a question for airflow's documentation) – Charles Duffy Jan 24 '23 at 17:38

1 Answers1

0

The [[ is a shell command (technically, a keyword) and requires whitespace between it and its arguments. You might be seeing an error [[0: command not found.

Also, the "inner" quotes aren't escaped (bash doesn't need them here):

"if [[ $a -ge 1 ]]; then"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352