You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
* Update variables.mdAdded encryption option for cf_export; restructured cf_export section* Update variables.mdReplaced example yaml for encryption in cf_export* Update with build encryptionAdded section on encrypting build variables* Update variables.mdAdded feedback for build encryption and commented out cf_export encryption section* Update variables.md
Copy file name to clipboardExpand all lines: _docs/pipelines/variables.md
+93-25Lines changed: 93 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,15 @@ Codefresh provides a set of predefined variables automatically in each build, th
17
17
18
18
There are two ways to use a Codefresh variable in your pipelines:
19
19
20
-
1. By default all variables will be exposed as UNIX environment variables in all freestyle steps as`$MY_VARIABLE_EXAMPLE`.
21
-
1. Variables can be used in YAML properties with the syntax {% raw %}`${{MY_VARIABLE_EXAMPLE}}`{% endraw %}.
20
+
1. Expose as UNIX environment variables
21
+
This is the default method, where all variables in all freestyle steps are exposed as UNIX environment variables:`$MY_VARIABLE_EXAMPLE`.
22
+
1. Directly in YAML properties
23
+
Use variables can be used in YAML properties with the syntax {% raw %}`${{MY_VARIABLE_EXAMPLE}}`{% endraw %}.
22
24
23
25
>If you are unsure about which form you need to use, feel free to use {% raw %}`${{MY_VARIABLE_EXAMPLE}}`{% endraw %} everywhere. This is the Codefresh specific form and should function in all sections of`codefresh.yml`.
24
26
25
-
For example, you can print out the branch as an environment variable like this:
27
+
**Example: Print out the branch as an environment variable**
28
+
In this example, we use simple`echo` commands, but any program or script that reads environment variables can also read them in the same manner.
26
29
27
30
`YAML`
28
31
{% highlight yaml %}
@@ -36,9 +39,8 @@ MyOwnStep:
36
39
{% endraw %}
37
40
{% endhighlight %}
38
41
39
-
In the example above we are using simple`echo` commands, but any program or script that reads environment variables could also read them in the same manner.
40
42
41
-
Using variables directly inyaml properties can be done like this:
43
+
**Example: Use directly inYAML properties**
42
44
43
45
`YAML`
44
46
{% highlight yaml %}
@@ -51,7 +53,8 @@ MyAppDockerImage:
51
53
{% endraw %}
52
54
{% endhighlight %}
53
55
54
-
You can also concatenate variables:
56
+
57
+
**Example: Concatenating variables**
55
58
56
59
`YAML`
57
60
{% highlight yaml %}
@@ -64,18 +67,16 @@ MyAppDockerImage:
64
67
{% endraw %}
65
68
{% endhighlight %}
66
69
67
-
This will create docker images with tags such as:
70
+
The concatenation above creates Docker images with tags such as:
68
71
69
72
```
70
73
master-df6a04c
71
74
develop-ba1cd68
72
75
feature-vb145dh
73
76
```
74
77
75
-
76
-
77
-
78
-
Notice that this syntax is specific to Codefresh and is**only** available within the Codefresh YAML file itself. If you want to write scripts or programs that use the Codefresh variables, you need to make them aware of the environment variable form.
78
+
>NOTE:
79
+
>This syntax is specific to Codefresh, and is**only** available within the Codefresh YAML file itself. If you want to write scripts or programs that use the Codefresh variables, you need to make them aware of the environment variable form.
79
80
80
81
81
82
##System variables
@@ -215,12 +216,16 @@ For example if a pipeline variable is defined both in project level and as an ex
215
216
216
217
##Exporting environment variables from a freestyle step
217
218
218
-
Steps defined inside steps are scoped to the step they were created in (even if you used the`export` command). In order to allow using variables across steps, we provide a shared file that facilitates variables importing and exporting. There are two ways to add variables to this file:
219
+
Steps defined within steps are scoped to the step they were created in (even if you used the`export` command). To use variables across steps, we provide a shared file through which you can import and export variables.
220
+
There are two ways to add variables to the shared file:
221
+
222
+
* Using the`cf_export` command
223
+
* Writing directly to the file
219
224
220
-
###Usingcf_export command
221
-
Within every freestyle step, the`cf_export` command allows you to export variables across steps(by writing to the shared variables file).
225
+
###Exporting variables with`cf_export`
226
+
Within every freestyle step, the`cf_export` command allows you to export variables across steps by writing to the shared variables file.
222
227
223
-
>The variables exportedwithcf_export overrides those at the pipeline-level.
228
+
>The variables exportedthrough`cf_export` overrides those at the pipeline-level.
224
229
225
230
You can either:
226
231
- Explicitly state a VAR=VAL pair
@@ -251,29 +256,68 @@ steps:
251
256
{% endraw %}
252
257
{% endhighlight %}
253
258
254
-
Notice that`cf_export` has the same syntax structure as the[bash export command](https://www.gnu.org/software/bash/manual/html_node/Environment.html){:target="\_blank"}. This means that when you use it you**don't** need any dollar signs for the variable created/assigned.
259
+
<br>
260
+
261
+
####`cf_export` syntax
262
+
263
+
`cf_export` has the same syntax as the[bash export command](https://www.gnu.org/software/bash/manual/html_node/Environment.html){:target="\_blank"}.
264
+
This means that when you use it you**don't** need any dollar signs for the variable that is created/assigned.
255
265
256
266
```
257
267
cf_export $MY_VAR # Don't do this
258
268
cf_export MY_VAR # Correct syntax
259
269
```
270
+
<!---
271
+
<br>
272
+
273
+
#### Encrypting variables within `cf_export`
274
+
275
+
Encrypt variables within `cf_export` by defining the `--mask` flag.
276
+
Values of encrypted variables in `cf_export` commands are replaced with asterisks in the Build variable list.
260
277
261
-
Also notice that`cf_export` works on*subsequent* steps only. If you want to export a variable right away in the present step and all the rest of the steps you need to do the following:
278
+
Here is an example with standard and encrypted versions of the same variable in `cf_export` commands.
By default,`cf_export` works only on*subsequent* steps.
302
+
To export a variable both in the current and to all the remaining steps, do the following:
262
303
263
304
```
264
-
export MY_VAR='example' #Will make MY_VAR available in this step only
265
-
cf_export MY_VAR='example' #Will also makeMY_VAR available to all steps after this one
305
+
export MY_VAR='example' #Makes MY_VAR available in this step only
306
+
cf_export MY_VAR='example' #MakesMY_VAR available also to all steps after this one
266
307
```
267
308
268
-
There is nothing really magic about`cf_export`. It is a normal script. You can see its contents on your own by entering the command`cat /codefresh/volume/cf_export` on any[Codefresh freestyle step]({{site.baseurl}}/docs/pipelines/steps/freestyle/) inside a pipeline.
269
309
270
-
For more information on its limitations see the[troubleshooting page]({{site.baseurl}}/docs/troubleshooting/common-issues/cf-export-limitations/).
310
+
There is nothing really magical about`cf_export`. It is a normal script. You can see its contents on your own by entering the command`cat /codefresh/volume/cf_export` on any[Codefresh freestyle step]({{site.baseurl}}/docs/pipelines/steps/freestyle/) inside a pipeline.
311
+
312
+
For more information on its limitations, see the[troubleshooting page]({{site.baseurl}}/docs/troubleshooting/common-issues/cf-export-limitations/).
271
313
272
314
273
315
274
316
###Directly writing to the file
275
317
276
-
For more advanced use cases, you can write directly to the shared variable file that Codefresh reads to understand which variables need to be available to all steps. This file has a simple format where each line is a variable and its value in the form of`VARIABLE=VALUE`. The`cf_export` command mentioned in the previous section is just a shorthand for writing on this file.
318
+
For more advanced use cases, you can write directly to the shared variable file that Codefresh reads to understand which variables need to be available to all steps.
319
+
320
+
This file has a simple format where each line is a variable and its value in the form of`VARIABLE=VALUE`. The`cf_export` command mentioned in the previous section is just a shorthand for writing on this file.
277
321
278
322
The variables file is available inside freestyle steps in the following path:**`{% raw %}${{CF_VOLUME_PATH}}{% endraw %}/env_vars_to_export`**
279
323
@@ -302,7 +346,7 @@ Use this technique if you have complex expressions that have issues with the `cf
302
346
303
347
##Masking variables in logs
304
348
305
-
Codefresh has the built-incapabililty to automatically mask variables in logs if they are encrypted. The values of encrypted variables will be replaced with asterisks in build logs.
349
+
Codefresh has the built-incapability to automatically mask variables in logs if they are encrypted. The values of encrypted variables will be replaced with asterisks in build logs.
306
350
307
351
{% include
308
352
image.html
@@ -329,8 +373,32 @@ max-width="60%"
329
373
>Notice that this feature is currently available only in Enterprise accounts.
330
374
331
375
332
-
##Escape characters
333
-
When passing special characters through environmental variables`\` can be used as an escape character. For example if you were passing a cassandra connection string you might do something like`Points\=hostname\;Port\=16376\;Username\=user\;Password\=password`
376
+
##Encrypt variables for pipeline build runs
377
+
378
+
When you run a pipeline manually, you can either add variables on the fly or change the value of existing variables for the specific run of the build.
379
+
You can also encrypt the build-specific variables, new or existing, at the same time.
380
+
381
+
1. Do one of the following:
382
+
* From the Pipelines page, select the pipeline and click**Run** on the right.
383
+
* From the Builds page, select the pipeline to run manually, and then click**Run**.
384
+
1. Expand Build Variables.
385
+
1. To add a variable, click**Add Variable**.
386
+
1. Enter the**Key** and**Value** for the new variable.
387
+
1. To encrypt, click {::nomarkdown}<imgsrc="../../../images/icons/encrypt.png"display=inline-block> <b>Encrypt</b>{:/}, and confirm.