How do you conditionally deploy a clientlib or component only in the AEM Stage or Prod environment in AEM as a Cloud Service - without using runmodes, which are no longer supported in the traditional sense?
Most documentation still refers to classic AEM paradigms. Curious to know how others have approached this in AEM Cloud-native setups.
Solved! Go to Solution.
Views
Replies
Total Likes
in Stage and PROD you cannot do that, as the same immutable content image is used for both. That means you need some runtime logic which achieves that.
(My question would be why this is even necessary ... I could imagine some cases, but have barely seen any really convincing case ...)
Hi @EthanRo5,
Since traditional runmode
-based includes (like clientlibs.<runmode>.js
) or Sling runmode folders (e.g., config.author
, config.publish
, etc.) aren't fully supported in AEMaaCS due to its immutable runtime model.
Use AEM Environment Variables and Context-Aware Configurations with Conditional Logic in HTL or JavaScript.
Use the Environment Indicator
service or create your own service that reads the environment type from:
com.adobe.granite.cloud.env
Or inject via AEM Environment Variable (Adobe I/O > Cloud Manager > Environment Variables
)
Example OSGi config value via context-aware:
@Designate(ocd = MyEnvConfig.class)
@Component(service = MyEnvService.class)
public class MyEnvServiceImpl implements MyEnvService {
@Activate
public void activate(MyEnvConfig config) {
this.environment = config.environmentType(); // dev/stage/prod
}
}
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class EnvModel {
@OSGiService
private MyEnvService myEnvService;
public String getEnvType() {
return myEnvService.getEnvironment(); // e.g., "stage"
}
}
<sly data-sly-use.env="com.myproject.models.EnvModel" />
<sly data-sly-test="${env.envType == 'stage' || env.envType == 'prod'}">
<cq:includeClientLib categories="my-secure-clientlib"/>
</sly>
I hope this will work.
Hi @EthanRo5 ,
Use environment variables via cloud manager
Set ENV variable in Cloud Manager pipeline:
Example: ENV_TYPE=stage
Access in Java code or Sling Model:
String env = System.getenv("ENV_TYPE");
Use in HTL to conditionally load clientlib:
<sly data-sly-test="${env == 'prod'}">
<script src="/etc.clientlibs/site/clientlibs/prod-only.js"></script>
</sly>
Hope this helpful.
Regards,
Karishma.
in Stage and PROD you cannot do that, as the same immutable content image is used for both. That means you need some runtime logic which achieves that.
(My question would be why this is even necessary ... I could imagine some cases, but have barely seen any really convincing case ...)
@EthanRo5 Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies