问题描述
我无法执行第二个arg语句:
"python","-c","from main import foo;print(foo('hello'))"
我正在使用Airflow运营商CloudBuildCreateBuildOperator触发Cloud Build。 触发DAG和Cloud Build均成功返回。
第一个安装requirements.txt文件的参数似乎根据Cloud Build返回的日志消息工作:
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","from main import foo;print(foo('hello'))"
],}],}
解决方法
如本示例here所述,使用Python链接命令并发送多个args
的最佳方法是在它们之间添加&&
。
下面是如何使用这种格式发送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触发器中使用多个参数。