Airflow Cloud Build Operator 未执行 python 函数

Airflow Cloud Build Operator not executing python function

我无法执行第二个 arg 语句:

"python", "-c", "from main import foo;print(foo('hello'))"

我正在使用 Airflow 运算符 CloudBuildCreateBuildOperator 触发 Cloud Build。 触发 DAG 和 Cloud Build return 成功。

根据 Cloud Build returned 日志消息,安装 requirements.txt 文件的第一个参数似乎有效:

Requirement already satisfied: setuptools>=40.3.0 in /usr/local/lib/python3.7/site-packages (from google-auth>=1.2->gcsfs>=0.6.2

我的函数正在使用 gcsfs 包。我在问题中使用的功能只是为了演示。

在使用 Airflow 之前,我在 yaml 文件中进行了此操作。 尝试了多种不同的陈述方式,例如:

"args":["-c","pip install -V -r requirements.txt; python -c from main import foo;print(foo('hello'))"]

但是现在在兜圈子

如果能帮助我使 args 语句正常工作,我将不胜感激。

这是来自 DAG 的 CloudBuildCreateBuildOperator:

create_build_from_storage_body = {
  "source": {
    "repoSource": {
      "projectId": "dev-6767",
      "repoName": "bq-pipeline",
      "branchName": "master",
    }
  },
  "steps": [{
    "name": "docker.io/library/python:3.7",
    "entrypoint": "/bin/bash",
    "args": ["-c", "pip install -V -r requirements.txt",
      "python", "-c", "from main import foo;print(foo('hello'))"
    ],
  }],
}

如本示例中所述here 链接命令并使用 Python 发送多个 args 的最佳方法是在它们之间添加一个 &&

下面是如何使用此格式为命令链发送参数的示例。

#testing1
steps:
- name: 'docker.io/library/python:3.7'
  id: Test
  entrypoint: /bin/sh
  args:
  - -c
  - 'pip install pytest && pip install -r requirements.txt && pytest test/*_test.py'
- name: gcr.io/google.com/cloudsdktool/cloud-sdk

这样一来,就可以在 Cloud Build 触发器中使用多个参数。