Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BashOperator - resolve bash by absolute path #25331

Merged
merged 1 commit into from Jul 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion airflow/operators/bash.py
Expand Up @@ -16,6 +16,7 @@
# specific language governing permissions and limitations
# under the License.
import os
import shutil
from typing import Dict, Optional, Sequence

from airflow.compat.functools import cached_property
Expand Down Expand Up @@ -174,14 +175,15 @@ def get_env(self, context):
return env

def execute(self, context: Context):
bash_path = shutil.which("bash") or "bash"
if self.cwd is not None:
if not os.path.exists(self.cwd):
raise AirflowException(f"Can not find the cwd: {self.cwd}")
if not os.path.isdir(self.cwd):
raise AirflowException(f"The cwd {self.cwd} must be a directory")
env = self.get_env(context)
result = self.subprocess_hook.run_command(
command=['bash', '-c', self.bash_command],
command=[bash_path, '-c', self.bash_command],
env=env,
output_encoding=self.output_encoding,
cwd=self.cwd,
Expand Down