問題描述
在管道任務中指定運行時參數 (Specify runtime parameter in a pipeline task)
我們需要以某種方式將動態運行時參數傳遞給管道任務。例如下面的參數 APPROVAL 對於任務的每次運行都是不同的。此 APPROVAL 參數用於更改和發布編號,以便任務可以在為審計目的而創建的 Terraform 資源上標記它。
在網上搜索了一段時間但沒有找到解決方案,是這可能在大廳管道或最佳實踐中?
‑ task: plan‑terraform
file: ci/concourse‑jobs/pipelines/tasks/terraform/plan‑terraform.yaml
params:
ENV: dev
APPROVAL: test
CHANNEL: Developement
GITLAB_KEY: ((gitlab_key))
REGION: eu‑west‑2
TF_FOLDER: terraform/squid
input_mapping:
ci: ci
tf: squid
output_mapping:
plan: plan
tags:
‑ dev
參考解法
方法 1:
From https://concourse‑ci.org/tasks.html: ideally tasks are pure functions: given the same set of inputs, it should either always succeed with the same outputs or always fail.
A dynamic parameter would break that contract and produce different outputs from the same set of inputs. Could you possibly make APPROVAL an input? Then you'd maintain your build traceability. If it's a (file) input, you could then load it into a variable:
APPROVAL=$(cat <filename>)
(by Alastair Montgomery、Brian S)