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
Copy file name to clipboardExpand all lines: _docs/pipelines/variables.md
+84-66Lines changed: 84 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,8 @@ redirect_from:
7
7
-/docs/codefresh-yaml/variables/
8
8
toc:true
9
9
---
10
-
Variables in pipelines allow you to parameterize the way your pipeline works. Codefresh provides a set of system variables, and the capability to define custom variables.
10
+
Variables in pipelines allow you to parameterize the way your pipeline works.
11
+
Codefresh provides a set of system variables, and also provides the capability to define custom variables.
11
12
12
13
*[System variables](#system-variables) are predefined variables prefixed with`CF`.
13
14
System variables are automatically included in every pipeline build. Here are some examples of system variables.
@@ -16,15 +17,16 @@ Variables in pipelines allow you to parameterize the way your pipeline works. Co
16
17
*`CF_BUILD_URL` is the url of the pipeline build.
17
18
18
19
*[User-defined variables](#user-defined-variables) are custom variables which you create.
19
-
You can create user-defined variables for different entities in Codefresh, such as projects, pipelines and steps, with or without a default value. You can also import variables you may have already defined.
20
+
You can create user-defined variables for different entities such as projects, pipelines and steps, with or without default values. You can also import variables you may have already defined.
21
+
20
22
21
23
Codefresh supports[two syntaxes](#using-codefresh-variables-in-pipelines) for variables: the UNIX syntax, and a proprietary syntax for use in YAML files.
22
24
23
25
##Using Codefresh variables in pipelines
24
26
25
27
There are two ways to use a Codefresh variable in your pipelines:
26
28
27
-
1. Expose as UNIX environment variables
29
+
1. Expose as UNIX environment variables
28
30
This is the default method. All variables in all[`freestyle`]({{site.baseurl}}/docs/pipelines/steps/freestyle/) steps are exposed as UNIX environment variables. For example,`$MY_VARIABLE_EXAMPLE`.
29
31
1. Directly in YAML properties
30
32
This format, specific to Codefresh, can be used in in YAML properties with the syntax {% raw %}`${{MY_VARIABLE_EXAMPLE}}`{% endraw %}.
@@ -53,7 +55,7 @@ MyOwnStep:
53
55
54
56
{% endraw %}
55
57
56
-
### Example: Use directly in YAML properties
58
+
### Example: Usevariabledirectly in YAML properties
57
59
58
60
`YAML`
59
61
{% raw %}
@@ -99,6 +101,7 @@ feature-vb145dh
99
101
100
102
System variables are automatically injected to any freestyle step as environment variables.
101
103
104
+
##### Git-based system variables
102
105
The values of Git-based system variables, such as `CF_BRANCH`, `CF_COMMIT_MESSAGE`, `CF_REVISION` etc. are retrieved directly from the Git provider you use, and therefore have the same limitations of that provider.
103
106
104
107
For example, GitLab sends less information in Pull Request (PR) events than normal pushes, and Bitbucket sends only the short hash of a commit in PR events. We suggest you read the documentation of your Git provider first to understand what information is available for every Git event.
@@ -261,67 +264,113 @@ Gerrit has no explicit concept of PRs as in other version control systems to map
261
264
262
265
## User-defined variables
263
266
264
-
User-defined variables are custom variables you add to Codefresh entities such as projects, pipelines, build triggers, and manual build runs.
265
-
You create such variables manually or by importing predefined variables from files (see [How to](#create-user-defined-variables)). You can also create empty variables, without any values.
267
+
User-defined variables are custom variables you add to CI entities such as projects, pipelines, build triggers, and manual build runs.
268
+
When adding a user-defined variable, you can create a:
269
+
270
+
* **Variable**
271
+
A standard variable whose value is visible in plain text unless explicitly encrypted. You can create these manually, import them from a file with predefined values, or define empty variables without assigned values.
272
+
* **Secret**
273
+
A variable whose value is automatically encrypted and masked in logs.
274
+
275
+
276
+
277
+
### Methods to define user-defined variables
278
+
279
+
These are the options available to add user-defined variables.
280
+
281
+
* **Add single variable**
282
+
Supported for all entities, this method allows you to add one variable at a time, with or without values.
283
+
You cannot encrypt empty variables.
284
+
* **Add multiple variables**
285
+
Add a set of variables by entering them manually, or by pasting them into the variable editor, one variable per line.
286
+
This is a quick option to add variables defined locally or in specific environments to a pipeline.
287
+
You simply copy the set of variables and paste them into the text editor.
288
+
* **Import from file**
289
+
Add predefined variables in bulk by importing from a file.
266
290
267
291
### Empty user-defined variables
268
292
269
-
Codefresh allowsyoutoadd variables with just the key definitions,without values. The valuesare automatically populated during pipeline execution or defined manually.
293
+
Ifyou add variables with just the key definitions,the valuesare automatically populated during pipeline execution orcan bedefined manually prior to build runs.
270
294
You can add empty variables to:
271
-
272
295
* Projects
273
296
* Pipelines
274
297
* Build triggers
275
298
276
299
> **NOTE**
277
300
> Encryption is not supported for empty variables.
278
301
279
-
### Import user-defined variables in bulk
280
-
281
-
Add custom variables in bulk by pasting them into the text editor or by importing them from a file.
282
-
283
-
* Import from text
284
-
This is a quick option to add variables defined locally or in specific environments to a pipeline.
285
-
You simply copy the set of variables and paste them into the text editor.
286
302
287
-
* Import from file
288
-
Importing from a file is useful when you have a file containing the predefined variables.
289
303
290
304
### Order of precedence for user-defined variables
291
305
292
-
In Codefresh, becuase you can add user-defined variables to different entities, variable definitions are available at levels.
293
-
294
-
If the variable with the same name is defined at multiple levels, the override rules are based on the priority of the variable. Variables at levels with higher priority override those at levels with lower priority.
306
+
Because you can add user-defined variables to different entities, you can have the same variables at different levels.
307
+
If the variable with the same name is defined for multiple entities, the override rules are based on the priority of the variable. Variables for entities with higher priority override those for entities with lower priority.
295
308
296
309
For example if a pipeline variable is defined both within a project, and as an execution parameter of a specific build, the final result will be the value of the variable defined as a build parameter. The project-level variable is ignored.
297
310
298
311
Listed below are the different levels for user-defined variables in order of priority, from the highest to the lowest.
299
312
300
-
1. Steps
313
+
1.**Steps**
301
314
* `export` command
302
315
Within the current step using [`export`](http://linuxcommand.org/lc3_man_pages/exporth.html){:target="\_blank"}, or in any **subsequent** step using [cf_export](#exporting-variables-with-cf_export) commands.
303
316
* [`freestyle`]({{site.baseurl}}/docs/pipelines/steps/freestyle/#examples) steps with `environment` field.
304
317
305
318
> **NOTE**
306
319
> Step-level variables with `export` take precedence over freestyle-step variables with `environment`.
307
-
1. Builds
320
+
1.**Builds**
308
321
* Within a specific build execution from the Codefresh UI or from the [CLI]({{site.baseurl}}/docs/integrations/codefresh-api/#example---triggering-pipelines).
The variables are injected into pipelines from different sources and at different levels. To view the variables actually used by a specific build of the pipeline, see [Viewing variables in pipeline builds]({{site.baseurl}}/docs/pipelines/monitoring-pipelines/#viewing-variables-in-pipeline-builds).
314
327
315
-
### Create user-defined variables
316
328
317
-
Create user-defined variables by selecting the target entity and then adding the variables.
318
329
319
-
#### Step 1: Select entity to which to add variables
330
+
### Add user-defined variables
331
+
332
+
1. Select the entity to which to add variables:
333
+
* [Projects](#projects)
334
+
* [Pipelines](#pipelines)
335
+
* [Steps](#steps)
336
+
* [Builds](#builds)
337
+
1. Select the type of variable to add:**Variable** or **Secret**.
You can create user-defined variables for projects, pipelines, build runs, and steps.
322
349
323
-
* **Projects**
324
-
In the row with the Project to which to add variables, click the **Settings** icon, and then click the **Variables** tab.
350
+
**Standard variables**
351
+
* Add single or multiple variables manually as key-value pairs, or import them in bulk from a file.
352
+
* To encrypt a variable, click {::nomarkdown}<img src="../../../images/icons/encrypt.png" display=inline-block alt="lock icon"> <b>Encrypt</b>{:/}, and confirm.
* Secrets are automatically encrypted and become immutable once saved.
366
+
* Decrypting a secret resets its value to empty.
367
+
368
+
369
+
370
+
371
+
372
+
##### Projects
373
+
From the list of **Projects**, select the Project to which to add variables, click the **Settings** icon, and then click the **Variables** tab.
325
374
326
375
{% include
327
376
image.html
@@ -333,9 +382,9 @@ You can create user-defined variables for projects, pipelines, build runs, and s
333
382
max-width="60%"
334
383
%}
335
384
336
-
* **Pipelines**
337
-
* In therow withthe Pipeline to which to add variables, click the **Settings** icon.
338
-
* Ontheright,click **Variables**.
385
+
#####Pipelines
386
+
* From thelist of pipelines, selectthe Pipeline to which to add variables.
387
+
* Click the **Settings** icon, clickthe**Workflow** tab, and thenclick **Variables** on the right.
339
388
340
389
{% include
341
390
image.html
@@ -347,11 +396,11 @@ You can create user-defined variables for projects, pipelines, build runs, and s
347
396
max-width="60%"
348
397
%}
349
398
350
-
* **Steps**
399
+
#####Steps
351
400
* Select the pipeline.
352
401
* In the **Workflow** tab, add the variable with the correct syntax to the step as required.
353
402
354
-
* **Builds**
403
+
#####Builds
355
404
* From the Builds page, in the Pipelines column, click the pipeline name.
356
405
* Click **Run**.
357
406
* Expand Build Variables.
@@ -366,42 +415,11 @@ You can create user-defined variables for projects, pipelines, build runs, and s
366
415
max-width="60%"
367
416
%}
368
417
369
-
#### Step 2: Add variables
370
418
371
-
Add variables manually by defining them as key-value pairs, or by importing them from files.
372
419
373
-
When adding variables, manually or through import, you can add/include empty variables, that is add only the key for the variable and leave the value empty to be dynamically or manually populated.
374
-
Apart from empty variables, you can also encrypt sensitive variables for reasons of security.
375
420
376
-
1. To manually add variables, click **Add Variable**.
377
-
* To add the variable with its default value, enter the key-value pair.
378
-
* To add an empty variable without a default value, simply type the key.
1. (Applies only to projects and pipelines) To import by copy and paste, click **Import from Text**:
392
-
* Copy the set of variables to add.
393
-
* Paste into the text editor.
394
-
* Click **Import**
395
-
{:start="3"}
396
-
1. (Applies only to projects and pipelines) To import them from a file, click **Import from File**:
397
-
* Browse to the file to import, and then click **Import**.
398
-
399
-
<!-- markdownlint-disable MD033 -->
400
-
{:start="4"}
401
-
1. Click **Save**.
402
-
1. To encrypt the variables (not supported for empty variables), click {::nomarkdown}<img src="../../../images/icons/encrypt.png" display=inline-block alt="lock icon"> <b>Encrypt</b>{:/}, and confirm.
403
-
404
-
<!-- markdownlint-enable MD033 -->
405
423
406
424
## Exporting environment variables from a freestyle step