Skip to content

Commit f07f11e

Browse files
authored
Update reusing-config.md
Added new parameter type env_var_name to Parameter Types section of content.
1 parent 70fadfb commit f07f11e

File tree

1 file changed

+97
-49
lines changed

1 file changed

+97
-49
lines changed

jekyll/_cci2/reusing-config.md

Lines changed: 97 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ This section describes the types of parameters and their usage. The parameter ty
380380
* enum
381381
* executor
382382
* steps
383+
* environment variable name
383384

384385
#### String
385386
{:.no_toc}
@@ -424,49 +425,33 @@ Boolean parameter evaluation is based on the [values specified in YAML 1.1](http
424425

425426
Capitalized and uppercase versions of the above values are also valid.
426427

427-
#### Steps
428+
#### Integer
428429
{:.no_toc}
429430

430-
Steps are used when you have a job or command that needs to mix predefined and user-defined steps. When passed in to a command or job invocation, the steps passed as parameters are always defined as a sequence, even if only one step is provided.
431+
The parameter type `integer` is use to pass a numeric integer value. The following example using the `integer` type to populate the value of `parallelism` in a job.
431432

432433
```yaml
433-
commands:
434-
run-tests:
435-
parameters:
436-
after-deps:
437-
description: "Steps that will be executed after dependencies are installed, but before tests are run"
438-
type: steps
439-
default: []
440-
steps:
441-
- run: make deps
442-
- steps: << parameters.after-deps >>
443-
- run: make test
444-
```
445-
446-
The following example demonstrates that steps passed as parameters are given as the value of a `steps` declaration under the job's `steps`.
434+
version: "2.1"
447435
448-
```yaml
449436
jobs:
450437
build:
438+
parameters:
439+
p:
440+
type: integer
441+
default: 1
442+
parallelism: << parameters.p >>
451443
machine: true
452444
steps:
453-
- run-tests:
454-
after-deps:
455-
- run: echo "The dependencies are installed"
456-
- run: echo "And now I'm going to run the tests"
457-
```
458-
459-
The above will resolve to the following:
445+
- checkout
460446
461-
```yaml
462-
steps:
463-
- run: make deps
464-
- run: echo "The dependencies are installed"
465-
- run: echo "And now I'm going to run the tests"
466-
- run: make test
447+
workflows:
448+
workflow:
449+
jobs:
450+
- build:
451+
p: 2
467452
```
468453

469-
#### Enum Parameter
454+
#### Enum
470455
{:.no_toc}
471456

472457
The `enum` parameter may be a list of any values. Use the `enum` parameter type when you want to enforce that the value must be one from a specific set of string values. The following example uses the `enum` parameter to declare the target operating system for a binary.
@@ -492,8 +477,9 @@ commands:
492477
type: enum
493478
default: "windows" #invalid declaration of default that does not appear in the comma-separated enum list
494479
enum: ["darwin", "linux"]
495-
```
496-
#### Executor parameter
480+
```
481+
482+
#### Executor
497483
{:.no_toc}
498484

499485
Use an `executor` parameter type to allow the invoker of a job to decide what
@@ -534,30 +520,97 @@ workflows:
534520
name: xenial
535521
some-value: foobar
536522
```
537-
#### Integer Parameter
523+
524+
#### Steps
538525
{:.no_toc}
539526

540-
The parameter type `integer` is use to pass a numeric integer value. The following example using the `integer` type to populate the value of `parallelism` in a job.
527+
Steps are used when you have a job or command that needs to mix predefined and user-defined steps. When passed in to a command or job invocation, the steps passed as parameters are always defined as a sequence, even if only one step is provided.
541528

542529
```yaml
543-
version: "2.1"
530+
commands:
531+
run-tests:
532+
parameters:
533+
after-deps:
534+
description: "Steps that will be executed after dependencies are installed, but before tests are run"
535+
type: steps
536+
default: []
537+
steps:
538+
- run: make deps
539+
- steps: << parameters.after-deps >>
540+
- run: make test
541+
```
544542

543+
The following example demonstrates that steps passed as parameters are given as the value of a `steps` declaration under the job's `steps`.
544+
545+
```yaml
545546
jobs:
546547
build:
547-
parameters:
548-
p:
549-
type: integer
550-
default: 1
551-
parallelism: << parameters.p >>
552548
machine: true
553549
steps:
554-
- checkout
550+
- run-tests:
551+
after-deps:
552+
- run: echo "The dependencies are installed"
553+
- run: echo "And now I'm going to run the tests"
554+
```
555+
556+
The above will resolve to the following:
557+
558+
```yaml
559+
steps:
560+
- run: make deps
561+
- run: echo "The dependencies are installed"
562+
- run: echo "And now I'm going to run the tests"
563+
- run: make test
564+
```
565+
#### Environment Variable Name
566+
567+
The environment variable name (``env_var_name``) parameter is a string that must match a POSIX_NAME regexp (e.g. no spaces or special characters) and is a more meaningful parameter type that enables additional checks to be performed. An example of this parameter is shown below.
555568

569+
```
570+
version: 2
571+
jobs:
572+
build:
573+
docker:
574+
- image: ubuntu:latest
575+
steps:
576+
- run:
577+
command: |
578+
s3cmd --access_key ${FOO_BAR} \
579+
--secret_key ${BIN_BAZ} \
580+
ls s3://some/where
556581
workflows:
557582
workflow:
558583
jobs:
559-
- build:
560-
p: 2
584+
- build
585+
version: 2
586+
587+
Original config.yml file:
588+
version: 2.1
589+
jobs:
590+
build:
591+
parameters:
592+
access-key:
593+
type: env_var_name
594+
default: AWS_ACCESS_KEY
595+
secret-key:
596+
type: env_var_name
597+
default: AWS_SECRET_KEY
598+
command:
599+
type: string
600+
docker:
601+
- image: ubuntu:latest
602+
steps:
603+
- run: |
604+
s3cmd --access_key ${<< parameters.access-key >>} \\
605+
--secret_key ${<< parameters.secret-key >>} \\
606+
<< parameters.command >>
607+
workflows:
608+
workflow:
609+
jobs:
610+
- build:
611+
access-key: FOO_BAR
612+
secret-key: BIN_BAZ
613+
command: ls s3://some/where
561614
```
562615
563616
## Authoring Parameterized Jobs
@@ -590,7 +643,6 @@ workflows:
590643

591644
**Note:** Invoking jobs multiple times in a single workflow and parameters in jobs are available in configuration version 2.1 and later.
592645

593-
594646
### Jobs Defined in an Orb
595647

596648
If a job is declared inside an orb it can use commands in that orb or the global commands. It is not possible to call commands outside the scope of declaration of the job.
@@ -631,7 +683,6 @@ workflows:
631683
saywhat: Everyone
632684
```
633685
634-
635686
### Using Parameters in Executors
636687
{:.no_toc}
637688
@@ -848,6 +899,3 @@ workflows:
848899
```
849900

850901
**Note:** Conditional steps are available in configuration version 2.1 and later.
851-
852-
853-

0 commit comments

Comments
 (0)