> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/database-devops/3.0/setup-db-devops/using-custom-script.md).

# Use Custom Script for Harness Database DevOps

Learn how to use a custom script to retrieve and manage a Liquibase changelog in Harness Database DevOps, including DB Schema setup and pipeline configuration.

In certain Database DevOps workflows, users may prefer or require a **custom script** to retrieve and manage their Liquibase changelog rather than using a connector or direct integration.

This guide provides a comprehensive overview of how to use a custom script for Database DevOps, including the creation of a DB Schema, deployment of the schema, and the use of pipeline variables.

## Use case

This guide supports the following scenario:

* The customer maintains a Liquibase changelog in a remote repository (for example, GitHub or JFrog). This is particularly useful when the changelog is stored in a repository for which Harness does not provide a native connector.
* They want to download and extract this changelog dynamically via a custom shell script.
* The script can reference **pipeline variables**, such as build versions or access tokens.

{% hint style="info" %}
Before proceeding, ensure you have set up a **Docker Registry Connector** to define the custom base image used in your pipeline. Go to [Docker Connector Settings Reference](/harness-platform/3.0/harness-platform-resources/connectors/cloud-providers/ref-cloud-providers/docker-registry-connector-settings-reference.md) to configure this connector.
{% endhint %}

## Deploy using a custom script

By following these steps, you can effectively manage your database changes and streamline your DevOps processes.

### Create a DB schema

1. Under **Database DevOps** in the Harness UI, navigate to **DB Schema**.
2. Select **Add New DB Schema**.

![](https://363656700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2pV6NGg9g53LONdeVP3y%2Fuploads%2Fgit-blob-fd68a35dc684b603e1a22a19dd3d081e145bd465%2Fdb-devops-custom-script-add-schema.png?alt=media)

* **Connect to Data Schema**: Connect via Harness Connector or use a custom script to connect to the database schema stored in a remote repository.
* **Schema Path**: The path to the schema file in the repository. This is where the custom script writes the changelog files that Database DevOps should use during pipeline execution.
* **Image**: The Docker image to be used for the custom script. This should be a base image that has the necessary tools and libraries installed to execute your script.
* **Shell**: The shell to be used for executing the script. This can be `bash` or `sh`, both of which are supported by the Docker image.
* **Script**: The custom script that runs. This script should include the logic to download and extract the changelog file from the remote repository.

For example:

```
curl -H 'Authorization: token <+secrets.getValue("github")>'
 -H 'Accept: application/vnd.github.v3.raw'
 -L https://api.github.com/repos/Sonichigo/mux-sql/contents/liquibase.yml?ref=main -o changelog.yml
```

{% hint style="info" %}
If your custom script requires variables or parameters, you can reference them using JEXL expressions. For example, you can reference file secrets securely by their ID. Go to [Reference by ID](/harness-platform/3.0/harness-platform-resources/secrets/add-file-secrets.md#reference-by-id) to use file secrets in your script. To learn how Database DevOps supports runtime secrets specifically, go to [Runtime secrets for DBOps](/database-devops/3.0/use-db-devops/database-authentication-and-security/runtime-secrets.md) to configure runtime secrets for Database DevOps.
{% endhint %}

3. Select **Save**.
4. The DB Schema is created, and you can see the details in the UI.
5. Select the **DB Schema**, and then select **Add New DB Instance**.

![](https://363656700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2pV6NGg9g53LONdeVP3y%2Fuploads%2Fgit-blob-c2fb99c37ebe845678c5e944038b9bcfd1db42f3%2Fdb-devops-custom-script-add-instance.png?alt=media)

* **Name of DB Instance**: The name of the DB Instance. This is the name that is used in the pipeline to refer to this DB Instance.
* **Tags (optional)**: Tags to be used for the DB Instance. This can be used to change which instances are shown on the migration state dashboard. If left blank, the tags are automatically generated.
* **Connector**: The JDBC Connector to be used for the DB Instance. This is the connector that connects to the database instance.
* **Context**: The context is used to control which changelogs are deployed to which environments. This is useful when you have multiple environments (for example, dev, test, and prod) and you want to deploy different changelogs to each environment.

### Deployment pipeline

1. Under **Database DevOps** in the Harness UI, navigate to **Pipelines**.
2. Select **Create a Pipeline**.
3. Select **Add Stage**, and then select **Custom Stage**.
4. In the **Stage** section, create **Add Step Group** as the stage type.

{% hint style="info" %}
Toggle on **Enable container based execution**.
{% endhint %}

5. In the **Step Group** section, select **Add Step** as the step type. Under **DB DevOps**, select **Apply Schema** as the step type.

![](https://363656700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2pV6NGg9g53LONdeVP3y%2Fuploads%2Fgit-blob-e374bb0fc3bc1153e579b5ce2f313123118a9ed4%2Fdb-devops-custom-script-apply-schema-step.png?alt=media)

* **Select DB Schema**: The DB Schema created earlier.
* **Select DB Instance**: The name of the DB Instance, which was created earlier in the DB Schema.
* **Tags (optional)**: Tags to be used for the DB Instance. This can be used to identify the DB Instance in the pipeline. If left blank, the tags are automatically generated.

6. Select **Apply Changes**, and then select **Save**.
7. The pipeline is created, and you can see the details in the UI.
8. Select **Run** to run the pipeline.

**Final result**

{% tabs %}
{% tab title="Visual Overview" %}
![](https://363656700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2pV6NGg9g53LONdeVP3y%2Fuploads%2Fgit-blob-d358db65e220a2b9ca70143f9ca352ffe0df18c2%2Fdb-devops-custom-script-pipeline-visual.png?alt=media)
{% endtab %}

{% tab title="YAML Overview" %}

```yaml
pipeline:
  name: custom-changelog-script
  identifier: customchangelogscript
  projectIdentifier: default_project
  orgIdentifier: default
  tags: {}
  stages:
    - stage:
        name: deploy
        identifier: deploy
        description: "Deploy DB Schema using Custom Script"
        type: Custom
        spec:
          execution:
            steps:
              - stepGroup:
                  name: apply schema
                  identifier: apply_schema
                  steps:
                    - step:
                        type: DBSchemaApply
                        name: DBSchemaApply_1
                        identifier: DBSchemaApply_1
                        spec:
                          connectorRef: dockerHarness
                          dbSchema: customscript
                          dbInstance: test3
                          tag: my-deployment
                        timeout: 10m
                  stepGroupInfra:
                    type: KubernetesDirect
                    spec:
                      connectorRef: db
            rollbackSteps: []
          serviceDependencies: []
        tags: {}
```

{% endtab %}
{% endtabs %}

You have created a DB Schema and deployed it using a custom script. You can use this pipeline to deploy your DB Schema to the database instance.

## Next steps

* Go to [Automated rollback for database schemas](/database-devops/3.0/use-db-devops/deployment-pipeline-configuration/rollback-and-failure-strategies/rollback-for-database-schemas.md) to configure automated rollback for failed deployments.
* Go to [Configure Author DB Change](/database-devops/3.0/use-db-devops/create-database-updates/configure-llm-for-database-devops.md) to use LLM-powered change authoring.
* Go to the [Troubleshooting Guide](/database-devops/3.0/troubleshooting-and-resources/troubleshooting-guide/troubleshooting.md) to resolve common setup and runtime errors.

{% @harness-feedback/feedback %}
