> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle Jobs

> Execute jobs during environment lifecycle events

## Overview

A Lifecycle Job is a Kubernetes job that is triggered by environment lifecycle events (deploy, stop, or delete). Unlike Cron Jobs that run on a schedule, Lifecycle Jobs execute when specific environment events occur.

**Key Features**:

* Triggered by environment events (deploy, stop, delete)
* Can output variables to other services in the environment
* Supports both Git and Container Registry sources

**Common Use Cases**:

* [Seed databases in preview environments](/getting-started/guides/others/database-seeding-lifecycle-job)
* Create external resources not managed by Qovery (S3 buckets, DNS records)
* Run database migrations
* Generate dynamic configuration or API keys
* Clean up resources on environment deletion

## Deployment Sources

Qovery supports two deployment sources for Lifecycle Jobs:

### Git Repository

Qovery pulls your code from a Git repository, builds the application, and deploys it to your Kubernetes cluster.

**Supported Providers**: GitHub, GitLab, Bitbucket

### Container Registry

Qovery pulls a pre-built container image from your configured registry and deploys it to your Kubernetes cluster.

## Creating a Lifecycle Job

<Steps>
  <Step title="Select Source">
    Choose **Git Repository** or **Container Registry** as your deployment source
  </Step>

  <Step title="Configure Source">
    **For Git Repository**:

    * Select Git provider
    * Choose repository
    * Select branch
    * Specify root path (if not at repository root)
    * Configure Dockerfile path

    **For Container Registry**:

    * Select configured registry
    * Enter image name
    * Specify image tag
  </Step>

  <Step title="Configure Triggers">
    Select which lifecycle events should trigger this job:

    * **Deploy**: Run when environment is deployed
    * **Stop**: Run when environment is stopped
    * **Delete**: Run when environment is deleted

    For each selected event, configure:

    * Custom entrypoint (optional)
    * CMD arguments (optional)
    * Restart policy
    * Max duration
    * Port (if needed for health checks)
  </Step>

  <Step title="Configure Resources">
    * **vCPU**: Default 500m (0.5 cores)
    * **RAM**: Default 512MB
  </Step>

  <Step title="Input Variables">
    Configure environment variables that the job needs
  </Step>

  <Step title="Review and Deploy">
    Review configuration and click **Create** to deploy
  </Step>
</Steps>

## Configuration

### General Settings

**Name**: Unique identifier for your Lifecycle Job within the environment

**Source Configuration**:

* Git: Provider, repository, branch, root path, Dockerfile path, build arguments, target stage
* Registry: Image name and tag

### Triggers

Configure which lifecycle events trigger this job:

**Deploy Event**:
Triggered when the environment is deployed. Use for:

* Running database migrations
* Seeding initial data
* Creating cloud resources
* Generating API keys or configuration

**Stop Event**:
Triggered when the environment is stopped. Use for:

* Creating backups
* Archiving data
* Notifying external systems

**Delete Event**:
Triggered when the environment is deleted. Use for:

* Cleaning up external resources
* Deleting cloud resources
* Removing API keys or tokens

For each event, configure:

* **Entrypoint**: Override container entrypoint
* **CMD Arguments**: Provide command arguments
* **Restart Policy**: Configure failure handling
* **Max Duration**: Execution timeout (in seconds)
* **Port**: For health checks (optional)

### Resources

* **vCPU**: CPU allocation in millicores (default: 500m)
* **Memory**: RAM allocation (default: 512MB)

### Input Variables

Lifecycle Jobs have access to:

* Built-in Qovery variables (environment ID, project ID, service connections)
* Custom environment variables
* Secrets

## Job Output Variables

Lifecycle Jobs can output data that gets injected as environment variables into other services in your environment.

### Output File

Write your output to:

```
/qovery-output/qovery-output.json
```

### Output Format

The output file must be valid JSON:

```json theme={null}
{
  "VARIABLE_NAME": {
    "sensitive": false,
    "value": "variable-value"
  },
  "API_KEY": {
    "sensitive": true,
    "value": "secret-key-value"
  }
}
```

**Fields**:

* **Key**: Variable name (will be prefixed with `QOVERY_OUTPUT_JOB_<JOB_ID>_`)
* **sensitive**: Boolean indicating if value is sensitive
* **value**: The actual value to inject

### Variable Naming

Output variables are automatically prefixed:

```
QOVERY_OUTPUT_JOB_<JOB_ID>_<VARIABLE_NAME>
```

Example: If your job outputs `API_KEY`, it will be available as:

```
QOVERY_OUTPUT_JOB_a1b2c3d4_API_KEY
```

### Using Output Variables

After the Lifecycle Job completes, output variables are automatically available to all services in the environment via environment variables.

## Force Run

Manually trigger a Lifecycle Job with a specific event type:

<Steps>
  <Step title="Navigate to Job">
    Go to your Lifecycle Job in the Qovery console
  </Step>

  <Step title="Click Force Run">
    Click the **Play** button or **Force Run** action
  </Step>

  <Step title="Select Event Type">
    Choose which event to simulate:

    * Deploy
    * Stop
    * Delete
  </Step>

  <Step title="Monitor Execution">
    View real-time logs and verify output variables are generated
  </Step>
</Steps>

<Info>
  Force Run allows testing specific event types without triggering the full environment lifecycle event.
</Info>

## Clone Service

You can create a clone of the service via the clone feature. A new service with the same configuration will be created into the target environment.

<Steps>
  <Step title="Select Job">
    Go to the Lifecycle Job you want to clone
  </Step>

  <Step title="Clone Job">
    Click on the **three dots button** and select **Clone**
  </Step>

  <Step title="Select Target Environment">
    Choose the target environment where you want to clone the service
  </Step>
</Steps>

<Info>
  The target environment can be the same as the current environment or a different one in a completely different project.
</Info>

<Note>
  Cloning excludes custom domains and some built-in environment variables to prevent conflicts.
</Note>

## Delete Lifecycle Job

To delete a Lifecycle Job:

1. Navigate to the Lifecycle Job settings
2. Click **Delete**
3. Confirm deletion

<Warning>
  Deleting a Lifecycle Job is permanent and cannot be undone.
</Warning>

## Related Resources

<CardGroup cols={2}>
  <Card title="Database Seeding Guide" icon="seedling" href="/getting-started/guides/others/database-seeding-lifecycle-job">
    Learn how to seed databases with Lifecycle Jobs
  </Card>

  <Card title="Cron Jobs" icon="clock" href="/configuration/cronjob">
    Schedule periodic jobs with CRON syntax
  </Card>

  <Card title="Environment Variables" icon="key" href="/configuration/environment-variables">
    Manage configuration and secrets
  </Card>

  <Card title="Deployment Pipeline" icon="diagram-project" href="/configuration/deployment/pipeline">
    Understand deployment flow and lifecycle
  </Card>
</CardGroup>
