在传递project-id时,cloudbuild.yaml文件中出现Regex错误



我正在尝试使用云构建运行数据流作业

steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
dataflow
jobs
run
google-template-job
--gcs-location=gs://dataflow-templates/latest/PubSub_Subscription_to_BigQuery
--parameters=inputSubscription='projects/$PROJECT_ID/subscriptions/messages'
--parameters=outputTableSpec="$PROJECT_ID:beam_samples.streaming_beam"
--staging-location=gs://cloudbuild-dataflow-testproject123456789-313307/tmp'
--region=us-central1

每次我触发构建时,我都会得到以下错误

ERROR: (gcloud.dataflow.jobs.run) INVALID_ARGUMENT: The template parameters are invalid.
- '@type': type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters
parameterViolations:
- description: 'Unmatched regex: ^projects/[^nr/]+/subscriptions/[^nr/]+$'
parameter: inputSubscription
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: step exited with non-zero status: 1

我的项目id中有一个"-",所以如果我用项目id的值替换$project_id,我仍然会得到同样的错误,有什么解决方法吗。我无法控制是否停止regex检查,因为它是谷歌提供的模板。

我如何通过这个

明白了。这只是命令解释器的问题。如果使用单引号,则会阻止对内部字符串进行任何求值。

在您的情况下

--parameters=inputSubscription='projects/$PROJECT_ID/subscriptions/messages'

'projects/$PROJECT_ID/subscriptions/messages'取为原样,因此项目ID包含大写和下划线,这违反了正则表达式模式。

更改为双引号,应该效果很好!

--parameters=inputSubscription="projects/$PROJECT_ID/subscriptions/messages"

最新更新