# Quick Start ⏱️

<div align="left"><figure><img src="/files/5vdabfbN99xkIgCFZ7hT" alt=""><figcaption></figcaption></figure></div>

## Install <a href="#install" id="install"></a>

Set up the Redefine CLI tool in your CI environment by copy-pasting the code below.

{% tabs %}
{% tab title="Pip Package Installer" %}

```bash
pip install -U redefine
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The Redefine CLI tool supports Python 3.6+ and is currently only available for CI environments, not the local developer's environment.
{% endhint %}

## Configure

#### Set up the authentication key

Store the Redefine authentication key in your CI system by following the recommended best practices for your specific CI platform: [GitHub Actions](https://docs.github.com/en/actions/security-guides/encrypted-secrets), [GitLab CI](https://docs.gitlab.com/ee/ci/secrets/#use-vault-secrets-in-a-ci-job), [Jenkins](https://www.jenkins.io/doc/developer/security/secrets/), [CircleCI](https://circleci.com/docs/security-recommendations/?utm_source=google\&utm_medium=sem\&utm_campaign=sem-google-dg--emea-en-dsa-tROAS-auth-brand\&utm_term=g_-c__dsa\&utm_content=\&gclid=CjwKCAjwo7iiBhAEEiwAsIxQEa7XGK25SIOM9uF6QmG77SjFOvDx-bFpR12qn1d_aXJ3ZxC2d_l5ThoCcBsQAvD_BwE), [Buildkite](https://buildkite.com/docs/pipelines/secrets), or [TeamCity](https://www.jetbrains.com/help/teamcity/security-notes.html#Recommended+Security+Practices). Once stored, you can export the authentication key to the Redefine CLI by setting the environment variable as `REDEFINE_AUTH`. This ensures that the CLI can access the authentication key securely and use it for authentication purposes.

{% hint style="info" %}
If you haven't received your Redefine credentials yet, please reach out to us at <help@redefine.dev>, We'd be happy to assist you!
{% endhint %}

#### Additional Configurations

{% hint style="info" %}
Check out [Configuration Parameters](/configuration/configuration-parameters.md) for additional configuration options.
{% endhint %}

## Verify

Once Redefine has been installed and configured, make sure that everything is working properly by running the `verify` command. This command verifies whether your CI environment is compatible with Redefine, and returns a success message if all is good or an error message detailing any issues that need fixing. To run the command, follow these steps:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine verify --pytest
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine verify --cypress
```

{% endtab %}

{% tab title="Mocha" %}

```bash
redefine verify --mocha
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For more information on successful verification output and examples of failure cases, check out [Verification Examples](/welcome-to-redefine/quick-start/verification-examples.md).
{% endhint %}

{% hint style="info" %}
For a full list of error messages and resolutions, see [Verify Troubleshooting](/troubleshooting/verify-troubleshooting.md).
{% endhint %}

## Run in Discover Mode

With Discover mode, Redefine analyzes your coding patterns and test results to create the initial test optimization model. To start the discovery process, simply replace the `verify` command from the previous step with the following command:

{% tabs %}
{% tab title="Pytest" %}

```bash
redefine install --discover --pytest
```

{% endtab %}

{% tab title="Cypress" %}

```bash
redefine install --discover --cypress
```

{% hint style="info" %}
If you are running Cypress using the flags `--project` or `--config-file`, Please add it to the 'redefine start' command as well.

For example:

```bash
redefine install --discover --cypress --project /path/to/project
redefine install --discover --cypress --config-file /path/to/file
```

{% endhint %}
{% endtab %}

{% tab title="Mocha" %}

```
redefine install --discover --mocha
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
For more information about selection modes, please see [Selection Modes](/configuration/selection-modes.md).
{% endhint %}

## Examples

The following examples show the final Redefine for development environments setup using `pytest`. This gives an idea of what your configuration should look like once everything is in place.

{% tabs %}
{% tab title="Github Actions" %}

```
- name: Redefine GitHub Action
    id: run_redefine
    uses: redefinedev/redefine-action@main
    with:
        auth: ${{ secrets.REDEFINE_AUTH_KEY }}
        testing-framework: pytest
        mode: discover
- name: Test with pytest  
    id: pytest 
    run: pytest tests
```

For all the GitHub Action options see the action's [docs](https://github.com/marketplace/actions/redefine-action).
{% endtab %}

{% tab title="Jenkins" %}

<pre class="language-bash"><code class="lang-bash">    stages {
        stage('run pytest with redefine') {
            environment {
                REDEFINE_AUTH=credentials('REDEFINE_AUTH_KEY')
            }
            steps {
                <a data-footnote-ref href="#user-content-fn-1">sh </a>'''
                pip install -U redefine
<strong>                redefine install --discover --pytest 
</strong>                pytest tests
                '''
            }
        }
</code></pre>

{% endtab %}

{% tab title="CircleCI" %}

```yaml
    name: run Redefine
    command: |
        pip install -U redefine
        redefine install --discover --pytest
    environment:
        REDEFINE_AUTH: $REDEFINE_AUTH_KEY
- run:
    name: test with pytest
    command: pytest tests
```

{% endtab %}

{% tab title="TeamCity" %}

<pre class="language-bash"><code class="lang-bash">export REDEFINE_AUTH=%secure:REDEFINE_AUTH_KEY%
<strong>export TEAMCITY_GIT_PATH=%teamcity.build.checkoutDir%
</strong>export TEAMCITY_HEAD_COMMIT_HASH=%build.vcs.number%
export TEAMCITY_PIPELINE_NAME=%teamcity.project.id%
export TEAMCITY_JOB_NAME=%system.teamcity.buildConfName%
export TEAMCITY_GIT_ACTION=%teamcity.pullRequest.branch.pullrequests%
export TEAMCITY_SOURCE_BRANCH=%teamcity.pullRequest.source.branch%
export TEAMCITY_TARGET_BRANCH=%teamcity.pullRequest.target.branch%

pip install -U redefine
redefine install --discover --pytest
pytest tests
</code></pre>

{% endtab %}

{% tab title="Gitlab CI" %}

```yaml
  id_tokens:
    VAULT_ID_TOKEN:
      aud: https://gitlab.com
  secrets:
    REDEFINE_AUTH:
      vault: production/redefine/auth_key@ops
      token: $REDEFINE_AUTH
  stage: test
  script:
    - pip install -U redefine
    - redefine install --discover --pytest 
    - pytest tests
```

{% endtab %}

{% tab title="Buildkite" %}

```yaml
steps:
  - label: "run pytest tests with redefine"
    command: | 
      # redefine expects an environment variable named REDEDINE_AUTH 
      # check the documentation on how to use a secret in buildkite: https://buildkite.com/docs/pipelines/secrets
      export REDEFINE_AUTH=<your-secret>
      pip install -U redefine
      redefine install --discover --pytest 
      pytest tests
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
**Tracking the discovery progress**

Monitor the progress of the discovery process and verify the data using the [Redefine Onboarding Wizard](https://app.redefine.dev/onboarding), which offers a user-friendly way to track the process and ensure accurate results.
{% endhint %}

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.redefine.dev/welcome-to-redefine/quick-start.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
