How to parameterize environment in edge.json of apigee-config-maven-plugin

Not applicable

Hi All,

My requirement is to change environments based on prod and nonprod orgs without editing edge.json file.

For example - in nonprod I have dev,test and in prod I have qa,prod environments. When I deploy in nonprod my product should be deployed in both dev,test and if prod my product should be deployed in qa,prod without editing edge.json file.

I am using shell script to run the maven command after few validations, Is that possible to replace shell variable $environment(which holds environments corresponding to organizations) in edge.json's like

"environment" : [$environment]; instead of "environment" : ["dev","test"];


Tagging @Madhan Sadasivam

0 7 2,090
7 REPLIES 7


Hi @Sathya Jayavel

Products are not environment configuration, they are organization level

Check out the sample edge.json, you will find configurations for apiProducts under orgConfig. With this, you configure products at the org level and can control using the build

If you are trying to update that existing config, then you might be able to do it using maven replacer plugin

For example

In your edge.json, you can have something like this

"orgConfig": {
        "apiProducts": [
            {
                "name": "EchoProduct",
                "apiResources": [
                    "/",
                    "/**"
                ],
                "approvalType": "auto",
                "attributes": [
                    {
                        "name": "description",
                        "value": "Echo Product"
                    }
                ],
                "description": "Echo Product",
                "displayName": "Echo Product",
                "environments": [
                    "edge_env"
                ],
                "proxies": [
                    "HelloWorld"
                ],
                "quota": "10000",
                "quotaInterval": "1",
                "quotaTimeUnit": "month",
                "scopes": []
            }        
        ],
        "developers": [],
        "developerApps": {}
    }

In your pom, you can include this plugin

<plugin>
  <groupId>com.google.code.maven-replacer-plugin</groupId>
  <artifactId>replacer</artifactId>
  <version>1.5.2</version>
  <executions>
    <execution>
      <phase>process-resources</phase>
      <goals>
        <goal>replace</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <basedir>${target.root.dir}</basedir>
    <includes>
      <include>edge.json</include> <!-- path to your edge.json -->
    </includes>
    <replacements>
      <replacement>
        <token>edge_env</token>
        <value>${envs}</value>
      </replacement>
    </replacements>
  </configuration>
</plugin>

And in your maven command, pass -Denvs=dev,test when you are deploying to non prod org and -Denvs=prod when you are deploying to prod org

Hope that clarifies

Hi Sai,

Its working great. But I have a problem, that is once I run maven with nonprod org the environments variable in edge.json gets replaced with non-prod environments. So if I run for prod, replace is not happening as there is no edge_env in edge.json instead it has previously altered nonprod environments.

What I have to do to make it work for both without manually changing edge.json?

I am not sure where I am going wrong. Can you please help me?

Sure @Sathya Jayavel - looks like you are moving in the right direction

For that, what I would do is, use the maven-resources-plugin and copy the resources to target folder and then use that in the replacer

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.6</version>
  <executions>
    <execution>
      <id>copy-resources</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <overwrite>true</overwrite>
        <resources>
          <resource>
            <!--source -->
            <directory>${project.root.dir}</directory>
            <filtering>true</filtering>
            <includes>
              <include>edge.json</include>
            </includes>
          </resource>
        </resources>
        <!--target -->
        <outputDirectory>${target.root.dir}</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Then use the below code as its using the file from target directory. This will not modify your source

<plugin>
  <groupId>com.google.code.maven-replacer-plugin</groupId>
  <artifactId>replacer</artifactId>
  <version>1.5.2</version>
  <executions>
    <execution>
      <phase>process-resources</phase>
      <goals>
        <goal>replace</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <basedir>${target.root.dir}</basedir>
    <includes>
      <include>edge.json</include> <!-- path to your edge.json -->
    </includes>
    <replacements>
      <replacement>
        <token>edge_env</token>
        <value>${envs}</value>
      </replacement>
    </replacements>
  </configuration>
</plugin>

Hope this clarifies

I am doing the same as mentioned but the apigee-config-maven-plugin refers to the source edge.json instead of edge.json that was copied and replaced. Can you please tell me how to change the path so it can refer to the copied edge.json.

Oh I guess the issue is that the plugin always looks for the edge.json file in the parent directory. I have opened a GitHub issue (#34) to include a property where you can pass another location instead of using the default

For now - can you move the config from edge.json to the directory structure as mentioned in this sample. By doing this, you can copy the contents to target directory, do the replace and in your maven command configure the -Dapigee.config.dir to point to your target directory. I have used this and would recommend this structure as with more config, your edge.json can grow and become complicated. With this directory approach, you can handle it easier

Is the issue resolved ?

1. I created another folder config under project root direcotry and placed edge.json file inside that.

2. Use maven copy resources plugin to copy from config direcotry to root directory.

3. run replace tokens plugin

Sample maven plugin

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<resources>
<resource>
<!--source -->
<directory>${project.root.dir}</directory>
<filtering>true</filtering>
<includes>
<include>apiproxy/**</include>
<include>test/integration/**</include>
<include>test/performance/**</include>
</includes>
</resource>
</resources>
<!--target -->
<outputDirectory>${target.root.dir}</outputDirectory>
</configuration>
</execution>
<execution>
<id>copy-resources2</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<resources>
<resource>
<!--source -->
<directory>${project.root.dir}/config</directory>
<filtering>false</filtering>
</resource>
</resources>
<!--target -->
<outputDirectory>${project.root.dir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>