Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
k6: grafana/k6@1.1.3
Use k6
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Executes a k6 test in the k6 Cloud. Ensure you set your K6_CLOUD_TOKEN on the CircleCI environment variables.
1
2
3
4
5
6
7
8
9
version: '2.1'
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
cloud: true
script: tests/cloud-test.js
Executes a k6 load test or reliability test on the currently used runner.
1
2
3
4
5
6
7
8
version: '2.1'
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
script: tests/api-stressing.js
Executes a test with arguments supplied to the k6 CLI. Any argument with either a CLI flag or an environment variable can be used here. For a full list of options, see https://k6.io/docs/using-k6/options
1
2
3
4
5
6
7
8
9
version: '2.1'
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
arguments: '--env SOME_ENV_VAR=some-value --compatibility-mode=base'
script: tests/some-test.js
Run a k6 test
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
arguments | Any command-line arguments, or flags, that you would like to pass on to k6. For a full list of options, see https://k6.io/docs/using-k6/options.
| No | '' | string |
cloud | Whether it runs the k6 test in the k6 Cloud. If true, set your K6_CLOUD_TOKEN on the CircleCI environment variables.
| No | false | boolean |
script | The path to your test script, relative to the current working directory
| No | test.js | string |
tag | Allows for overriding the tag used to pick a docker image for the k6 test job. | No | latest | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Run load tests and reliability tests using k6. This orb allows for running k6 tests locally on the runner and in the k6 Cloud.
display:
home_url: https://k6.io
source_url: https://github.com/grafana/k6-circleci-orb
jobs:
k6:
description: |
Run a k6 test
docker:
- image: loadimpact/k6:<< parameters.tag >>
parameters:
arguments:
default: ""
description: |
Any command-line arguments, or flags, that you would like to pass on to k6. For a full list of options, see https://k6.io/docs/using-k6/options.
type: string
cloud:
default: false
description: |
Whether it runs the k6 test in the k6 Cloud. If true, set your K6_CLOUD_TOKEN on the CircleCI environment variables.
type: boolean
script:
default: test.js
description: |
The path to your test script, relative to the current working directory
type: string
tag:
default: latest
description: Allows for overriding the tag used to pick a docker image for the k6 test job.
type: string
steps:
- checkout
- when:
condition: << parameters.cloud >>
steps:
- run:
command: |
k6 cloud << parameters.script >> << parameters.arguments >>
name: Execute cloud test
- unless:
condition: << parameters.cloud >>
steps:
- run:
command: k6 run << parameters.script >> << parameters.arguments >>
name: Local Execution
- store_artifacts:
path: /tmp/artifacts
examples:
test_cloud:
description: |
Executes a k6 test in the k6 Cloud.
Ensure you set your K6_CLOUD_TOKEN on the CircleCI environment variables.
usage:
version: "2.1"
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
cloud: true
script: tests/cloud-test.js
test_local:
description: |
Executes a k6 load test or reliability test on the currently used runner.
usage:
version: "2.1"
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
script: tests/api-stressing.js
test_with_args:
description: |
Executes a test with arguments supplied to the k6 CLI. Any argument with either a CLI flag or an
environment variable can be used here. For a full list of options, see https://k6.io/docs/using-k6/options
usage:
version: "2.1"
orbs:
grafana: grafana/k6@1.1.0
workflows:
load_test:
jobs:
- grafana/k6:
arguments: --env SOME_ENV_VAR=some-value --compatibility-mode=base
script: tests/some-test.js