use same targets default.xml for different env from CICD

Hi Team,

We have created Azure CICD pipeline and we are able to deploy the code in different Apigee Hybrid environments with using apigee maven plugin.  while deploying we found that we need to updated target end points based on environment, 

By default when we develop the proxy in dev environment and export the proxy bundle from apigee portal dev env, we will get target xml file with dev environment endpoints but when we push same bundle from CICD pipeline to different env(Dev,test,Prod) we need to update the target point manually after deployment.

Example:

Dev Env target connection

<HTTPTargetConnection>
<URL>https://dev-httpbin.org/get</URL>
</HTTPTargetConnection>

https://dev-httpbin.org/get--this backed url will be get change for every env like(https://tes-httpbin.org/get, https://qa-httpbin.org/get)

is there any way configure some place and will call backed target urls dynamically

Solved Solved
0 3 185
1 ACCEPTED SOLUTION

Nothing.  The "thing to update" is defined by the xpath as defined in the config.json .  You can have anything you like between the URL tags.  You need to specify the values you want, in the config.json.  Replace qa-mocktarget.apigee.net (and so on) with your chosen values.

 

 

View solution in original post

3 REPLIES 3

is there any way configure some place and will call backed target urls dynamically

Yes, there are options.

  1. One is to use a templating approach. Your target .xml file should contain a placeholder , that gets replaced via a template system, at the time the CI/CD pipeline runs. The Apigee team maintains a tool, the maven deploy plugin (repo here), that does this. As the name suggests, this is a plugin for the java-oriented maven build tool . In this case the plugin does not build a java app, but instead just combines data with the api proxy template. It takes an API proxy "template", replaces placeholders with values for different environments, and then packages that result up into an "importable api proxy bundle". Optionally, you can import that bundle, and then deploy it. OR you could use a different tool to import and deploy the bundle.
    An example target file is here in the samples folder of the repo for the maven deploy plugin. And an example configuration file is here. You can see that for each distinct environment, the configuration can hold different values for the target endpoint.
  2. Another option is to use named target servers. These are names that point to specific upstream systems. In environment dev, you might have a named target server called "upstream1" which points to dev-upstream.example.org while in environment test, you could have a target server with the same name, but which points to test-upstream.example.org. In this case you import and deploy the same proxy bundle to dev and test, but they implicitly use different target servers according to how you have set up the named target servers. Here is an older video describing how this works.
    Just a note - the examples in the documentation show the use of named target servers with the loadbalancer embedded within Apigee. This is not a requirement. Well it is a requirement to use a LoadBalancer element, but it is not a requirement to have multiple targets there. So you can use named target servers to solve your requirement.
  3. The last option I can think of is to use a properties file or KVM, which you can use at runtime in the API proxy to lookup the target URL. The target URL in an HTTPTargetConnection is a message template. So you can specify a variable name there, in which the context variable holds the URL. You will need to set the variable by reading a KVM or a settings/properties file. For example do a KVM lookup using a key including the environment name. This is basically a "manual" method of doing target servers, but you won't need to use the LoadBalancer element to employ this method.

Hi @dchiesa1 

Thanks for quick response. I would like to go with option 1.

example this is my config.json file.

{
"configurations": [
{
"name": "test",
"targets": [
{
"name": "default.xml",
"tokens": [
{
"xpath": "/TargetEndpoint/HTTPTargetConnection/URL",
"value": "https://dev-mocktarget.apigee.net"
}
]
}
]
},
{
"name": "qa",
"targets": [
{
"name": "default.xml",
"tokens": [
{
"xpath": "/TargetEndpoint/HTTPTargetConnection/URL",
"value": "https://qa-mocktarget.apigee.net"
}
]
}
]
}
]
}.

 

what value do i need to update between  <URL>https://replaced_by_config_json</URL>

<HTTPTargetConnection>

     <Properties/>

     <URL>https://replaced_by_config_json</URL>

   </HTTPTargetConnection>

Nothing.  The "thing to update" is defined by the xpath as defined in the config.json .  You can have anything you like between the URL tags.  You need to specify the values you want, in the config.json.  Replace qa-mocktarget.apigee.net (and so on) with your chosen values.