This is a skeleton project for starting a new _to be continuous_ template.
This project implements a generic GitLab CI template for loading test using [k6 loading test](https://k6.io/).
You shall fork it when you want to start developing a new template.
It provides several features, usable in different modes (by configuration).
Based on the kind of template (build, analyse, hosting, acceptance, ...), you should start working from one of the available `initial-xxx` branches, that each implement basic stuff.
## Usage
In order to include this template in your project, add the following to your `gitlab-ci.yml`:
```yaml
include:
-project:'to-be-continuous/k6'
ref:'1.0.0'
file:'/templates/gitlab-ci-k6.yml'
# Pipeline steps
stages:
-acceptance# required by Cypress template
# TODO: add all other required stages
```
:warning: depending on your needs and environment, you might have to use [one of the template variants](#variants).
| `K6_IMAGE` | The Docker image used to run k6 | `loadimpact/k6:latest` |
| `K6_TESTS_DIR` | The k6 tests directory | `k6` |
| `K6_EXTRA_ARGS` | k6 extra [command-line](https://k6.io/docs/getting-started/running-k6) | _none_ |
| `REVIEW_ENABLED` | Set to enable k6 tests on review environments (dynamic environments instantiated on development branches) | _none_ (disabled) |
### Load performance report integration
k6 test reports are [integrated to GitLab by generating load performance reports](https://docs.gitlab.com/ee/user/project/merge_requests/load_performance_testing.html).
This is done using the following CLI options: `--out json=reports/`
### Base URL auto evaluation
By default, the k6 template tries to auto-evaluate the base URL (i.e. the variable pointing at server under test) by
looking either for a `$environment_url` variable or for an `environment_url.txt` file.
Therefore if an upstream job in the pipeline deployed your code to a server and propagated the deployed server url,
either through a [dotenv](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportsdotenv) variable `$environment_url`
or through a basic `environment_url.txt` file, then the k6 test will automatically be run on this server.
:warning: all our deployment templates implement this design. Therefore even purely dynamic environments (such as review
environments) will automatically be propagated to your k6 tests.
In order to use the auto-evaluated base URL, you shall use the `base_url` environment variable from your k6 scripts.