[ 
https://issues.apache.org/jira/browse/AIRFLOW-502?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16687152#comment-16687152
 ] 

ASF GitHub Bot commented on AIRFLOW-502:
----------------------------------------

kaxil closed pull request #4184: [AIRFLOW-502] BashOperator success/failure 
conditions not documented
URL: https://github.com/apache/incubator-airflow/pull/4184
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/operators/bash_operator.py 
b/airflow/operators/bash_operator.py
index f9c2e1bbc0..dda56fa911 100644
--- a/airflow/operators/bash_operator.py
+++ b/airflow/operators/bash_operator.py
@@ -49,6 +49,17 @@ class BashOperator(BaseOperator):
     :type env: dict
     :param output_encoding: Output encoding of bash command
     :type output_encoding: str
+
+    On execution of this operator the task will be up for retry
+    when exception is raised. However, if a sub-command exits with non-zero
+    value Airflow will not recognize it as failure unless the whole shell exits
+    with a failure. The easiest way of achieving this is to prefix the command
+    with ``set -e;``
+    Example:
+    
+    .. code-block:: python
+        
+        bash_command = "set -e; python3 script.py '{{ next_execution_date }}'"
     """
     template_fields = ('bash_command', 'env')
     template_ext = ('.sh', '.bash',)
@@ -79,7 +90,8 @@ def execute(self, context):
         # Prepare env for child process.
         if self.env is None:
             self.env = os.environ.copy()
-        airflow_context_vars = context_to_airflow_vars(context, 
in_env_var_format=True)
+        airflow_context_vars = context_to_airflow_vars(context,
+                                                       in_env_var_format=True)
         self.log.info("Exporting the following env vars:\n" +
                       '\n'.join(["{}={}".format(k, v)
                                  for k, v in


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> BashOperator success/failure conditions not documented
> ------------------------------------------------------
>
>                 Key: AIRFLOW-502
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-502
>             Project: Apache Airflow
>          Issue Type: Improvement
>          Components: docs
>            Reporter: Li Xuanji
>            Assignee: Li Xuanji
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to