DevAn
DevAn

Reputation: 11

azure-spring-apps-maven-plugin with environment variables

I am trying to deploy on azure spring apps using azure-spring-apps-maven-plugin (v1.19.0) following is my configuration but somehow it is not updating environment variables in Azure Spring app. If I set environment variable manually from Azure portal then it is working but not sure why it is not working through maven.

I have already tried following configuration

<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-apps-maven-plugin</artifactId>
<!--<version>1.17.0</version> -->
<version>1.19.0</version>
<configuration>
    <subscriptionId>XXXXXXXXXX</subscriptionId>
    <appName>demo</appName>
    <resourceGroup>java-xxx-xxxx</resourceGroup>
    <clusterName>spring-java-apps</clusterName>
    <isPublic>true</isPublic>
    <advancedOptions>true</advancedOptions>
    <deployment>
        <cpu>1</cpu>
        <memoryInGB>2</memoryInGB>
        <instanceCount>1</instanceCount>
        <runtimeVersion>Java 17</runtimeVersion>
        <environment>                            <SPRING_PROFILES_ACTIVE>dev</SPRING_PROFILES_ACTIVE>
        </environment>
        <resources>
            <resource>
                <directory>${project.basedir}/target</directory>
                <includes>
                    <include>*.jar</include>
                </includes>
            </resource>
        </resources>
    </deployment>
</configuration>
</plugin>

Upvotes: 1

Views: 314

Answers (1)

Suresh Chikkam
Suresh Chikkam

Reputation: 3355

but somehow it is not updating environment variables in Azure Spring app.

  • The correct way to set environment variables using the azure-spring-apps-maven-plugin is to use the <property> element inside the <environment> element. Should not directly set inside the <environment> as a child element. Here's the corrected configuration.
<plugin>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-spring-apps-maven-plugin</artifactId>
    <version>1.19.0</version>
    <configuration>
        <subscriptionId>XXXXXXXXXX</subscriptionId>
        <appName>demo</appName>
        <resourceGroup>java-xxx-xxxx</resourceGroup>
        <clusterName>spring-java-apps</clusterName>
        <isPublic>true</isPublic>
        <advancedOptions>true</advancedOptions>
        <deployment>
            <cpu>1</cpu>
            <memoryInGB>2</memoryInGB>
            <instanceCount>1</instanceCount>
            <runtimeVersion>Java 17</runtimeVersion>
            <environment>
                <!-- Define your environment variables using <property> elements -->
                <property>
                    <name>SPRING_PROFILES_ACTIVE</name>
                    <value>dev</value>
                </property>
            </environment>
            <resources>
                <resource>
                    <directory>${project.basedir}/target</directory>
                    <includes>
                        <include>*.jar</include>
                    </includes>
                </resource>
            </resources>
        </deployment>
    </configuration>
</plugin>
  • With this corrected configuration, the SPRING_PROFILES_ACTIVE environment variable will be set to dev during the deployment process using the azure-spring-apps-maven-plugin.

Reference:

Upvotes: 1

Related Questions