Knowledge Base
Published Sep. 10, 2025

Persisting a Secret Environment Variable upon deleting and redeploying a service

Written By

Isaac Wilson

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Note: please note that Liferay has renamed its Liferay Experience Could offerings to Liferay SaaS (formerly LXC) and Liferay PaaS (formerly LXC-SM).

Issue

  • For business reasons, we have a custom service that we occasionally need to delete and recreate with a new deployment. However, when we delete the service, all secret variables previously attached to this service (using the UI) are no longer injected when the service is recreated, requiring us to go in and reattach each of the secrets.
  • Is there a way to persist secrets across a deletion and recreation event for a service?

Environment

  • Liferay PaaS

Resolution

The following steps and syntax leveraging the LCP.json can be used to ensure that a secret is injected into a service when that service is created (or even deployed, if attaching a new secret):

  1. Ensure that a secret has already been created within an environment, and is visible when viewing the "Secrets" section of the environment's Settings page (see: Adding a New Secret)
    Note: This secret does not need to currently be attached to any services under "Used in".
  2. Edit or add the env section in the service's LCP.json to include the following variable syntax:
    "DESIRED_VARIABLE_KEY" : "@nameofexistingsecret"
    For example, you can reference a secret named "examplename" in the LCP.json with this:
    "env": {
        "EXAMPLE_KEY": "@examplename"
    },
  3. Create a build including these changes, then deploy that build to the environment.
    When doing so, even if the secret was not previously attached to the service, the value saved in the examplename secret will be injected into the service during its startup process using the Key set in the LCP.json.

Additional Information

Did this article resolve your issue ?

Knowledge Base