【发布时间】:2018-03-13 14:22:10
【问题描述】:
我想在实际构建之前运行一个需要 cl 参数的 python 脚本,所以我在 .gitlab-ci.yml 中添加了以下部分:
.deploy_template: &template_name
variables:
- arg1: "https://some/url/"
- arg2: "https://another/url/"
- arg3: "https://one/more/url/"
script:
- python3 some/script/file.py $arg1 $arg2 $arg3
但我收到以下错误:
usage: file.py [-h] arg1 arg2 arg3
file.py: error: the following arguments are required: arg1 arg2 arg3
如果参数只是字符串(即不是变量),那么它可以正常工作,但它不会读取变量$arg1 等。
在 gitlab 文档中提到,我可以使用 bash 语法来提供变量,所以 $arg1 必须是正确的引用。
我在脚本中使用argparse 来获取 cl 参数。
将 gitlab-ci.yml 中的变量调用为 python 脚本参数的正确方法是什么?
【问题讨论】:
标签: python bash yaml command-line-arguments gitlab-ci