String parameters are used when you define environment variables, arguments, or images in a BuildStrategy
or ClusterBuildStrategy
custom resource (CR). In your build strategy steps, you can reference string parameters by using the $(params.your-parameter-name)
syntax.
|
You can also reference system parameters and strategy parameters by using the $(params.your-parameter-name) syntax in your build strategy steps.
|
In the pod, all $(params.your-parameter-name)
variables are replaced by actual strings. However, you must pay attention when you reference a string parameter in an argument by using an inline script. For example, to securely pass a parameter value into an argument defined with a script, you can choose one of the following approaches:
Example: Referencing a string parameter into an environment variable
You can pass the string parameter into an environment variable, instead of directly using it inside the script. By using quoting around the environment variable, you can avoid the command injection vulnerability. You can use this approach for strategies, such as buildah
. The following example uses an environment variable inside the script to reference a string parameter:
apiVersion: shipwright.io/v1beta1
kind: BuildStrategy
metadata:
name: sample-strategy
spec:
parameters:
- name: sample-parameter
description: A sample parameter
type: string
steps:
- name: sample-step
env:
- name: PARAM_SAMPLE_PARAMETER
value: $(params.sample-parameter)
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
some-tool --sample-argument "${PARAM_SAMPLE_PARAMETER}"
Example: Referencing a string parameter into an argument
You can pass the string parameter into an argument defined within your script. Appropriate shell quoting guards against command injection. You can use this approach for strategies, such as buildah
. The following example uses an argument defined within your script to reference a string parameter:
apiVersion: shipwright.io/v1beta1
kind: BuildStrategy
metadata:
name: sample-strategy
spec:
parameters:
- name: sample-parameter
description: A sample parameter
type: string
steps:
- name: sample-step
command:
- /bin/bash
args:
- -c
- |
set -euo pipefail
SAMPLE_PARAMETER="$1"
some-tool --sample-argument "${SAMPLE_PARAMETER}"
- --
- $(params.sample-parameter)