> 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/continuous-integration/troubleshooting-and-resources/ci-articles-and-faqs/articles/maven-settings-xml.md).

# Maven settings.xml

This topic provides guidance on storing and using Maven `settings.xml` with Harness CI. It is not exhaustive. This information is provided primarily to address some specific use cases for `settings.xml`.

### Where do I store Maven project settings.xml in Harness CI? <a href="#where-do-i-store-maven-project-settingsxml-in-harness-ci" id="where-do-i-store-maven-project-settingsxml-in-harness-ci"></a>

There are several options for handling `settings.xml` in Harness CI:

* Store `settings.xml` externally from Harness, such as in a version control repo, and then [use a Git Clone or Run step to clone that repo (or subdirectory of a repo) into your pipeline](/continuous-integration/use-harness-ci/use-harness-ci/codebase-configuration/clone-and-process-multiple-codebases-in-the-same-pipeline.md#add-a-git-clone-or-run-step).
* Store `settings.xml` as a file secret in Harness and then use a shell script in a Run step to copy the file to the relevant directory when your build runs.
* Store values for `settings.xml` as text secrets, and then add those values to a new `settings.xml` file that is created when your build runs. An example of this is shown in [Override secrets in settings.xml at runtime](#override-secrets-in-settingsxml-at-runtime).

You can use expressions to reference secrets in step commands, such as:

```
cat > settings.xml <<- EOM
<+secrets.getValue("account.[settingsXMLSecretID]")>
EOM
```

If you need to share `settings.xml` with multiple steps in the same stage, declare it in **Shared Paths**. For more information, go to [Share data between steps in a stage](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/share-ci-data-across-steps-and-stages.md).

### Override secrets in settings.xml at runtime <a href="#override-secrets-in-settingsxml-at-runtime" id="override-secrets-in-settingsxml-at-runtime"></a>

Use the following steps to override secrets in a [Maven settings.xml file](https://maven.apache.org/settings.html) by modifying the [Build stage settings](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/ci-stage-settings.md) when the pipeline runs.

These steps assume you have an understanding of the [Harness Secret Manager](/harness-ai/use-harness-platform/secrets/secrets-management/harness-secret-manager-overview.md) or that you know how to [add your own secrets manager](/harness-ai/troubleshooting-and-resources/tutorials/add-secrets-manager.md). You should also be familiar with [adding text secrets](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md), [adding file secrets](/harness-ai/use-harness-platform/secrets/add-file-secrets.md), and [adding SSH secrets](/harness-ai/use-harness-platform/secrets/add-use-ssh-secrets.md).

#### Create a secret at the account scope <a href="#create-a-secret-at-the-account-scope" id="create-a-secret-at-the-account-scope"></a>

Create a [text secret](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md) at the [account scope](/harness-ai/use-harness-platform/platform-access-control.md#permissions-hierarchy-scopes) that contains the content of your `settings.xml` file.

You need permissions to create, edit, and view secrets at the account scope to be able to do this. For more information, go to the [Permission Reference](/harness-ai/use-harness-platform/platform-access-control/permissions-reference.md).

1. Go to **Account Settings**, select **Account Resources**, and then select **Secrets**.
2. Select **New Secret**, and then select **Text**.
3. Enter a **Secret Name**, such as `settingsXML`. Take note of the **ID**. You need it to reference the secret in your pipeline.
4. In **Secret Value**, paste the XML settings content from your `settings.xml` file, and then select **Save**.

![](/files/CB7UPUNip7wfCQSL0PLG)

### Transcribe the text secret into settings.xml <a href="#transcribe-the-text-secret-into-settingsxml" id="transcribe-the-text-secret-into-settingsxml"></a>

Create a new `settings.xml` file in the Harness working directory (`/harness`) and include a command in your pipeline to assign the value of your settings XML text secret to that file. To do this, modify the [Run step](/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) or [Test step](/continuous-integration/use-harness-ci/use-harness-ci/run-tests/tests-v2.md) where your Maven tests run.

{% tabs %}
{% tab title="Run or Test step" %}
If your Maven tests run in a **Run** or **Test** step, add the following to the **Command**:

```
cat > settings.xml <<- EOM
<+secrets.getValue("account.settingsXML")>
EOM
```

{% endtab %}

{% tab title="Run Tests step (deprecated)" %}
If your Maven tests run in a **Run Tests** step, add the following to the **Pre-Command**:

```
cat > settings.xml <<- EOM
<+secrets.getValue("account.settingsXML")>
EOM
```

{% endtab %}
{% endtabs %}

#### Modify the Maven test command <a href="#modify-the-maven-test-command" id="modify-the-maven-test-command"></a>

Once the `settings.xml` file exists in the Harness working directory, Maven can read your text secret from this file if you run `mvn test` with the `-s` flag. For example:

```
mvn test -s settings.xml
```

#### Optional: Use the .m2 directory <a href="#optional-use-the-m2-directory" id="optional-use-the-m2-directory"></a>

If your `settings.xml` file is in the `~/.m2/` directory, Maven can read the secrets from the default location and you don't need to run `mvn test` with `-s` flag.

For example, if you can use the following command to transcribe the [settings.xml text secret](#transcribe-the-text-secret-into-settingsxml) to `~/.m2/`:

```
cat > ~/.m2/settings.xml <<- EOM
<+secrets.getValue("account.settingsXML")>
EOM
```

And then you only need `mvn test` to run the test.
