Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Pipeline Variables For Staging Slot Only

Avatar

Level 2

Hi team, 

 

I am in the process of building a website using AEM Sites, utilizing SPA Components and SSR. For this, I am using the standard AEM Archetype (https://github.com/adobe/aem-project-archetype), with the appropriate flags (enableSSR etc). 

 

Part of this, is a POM file which reads pipeline variables and sets them as variables for the build. An example of this, specifically for SSR can be seen here : https://github.com/adobe/aem-project-archetype/blob/23fea9f0a64fc5715ff7f28fca19cb720c355a79/src/mai...

This is then used in the deployment step of the front end, to deploy the application to Adobe IO for server side rendering here : https://github.com/adobe/aem-project-archetype/blob/23fea9f0a64fc5715ff7f28fca19cb720c355a79/src/mai...

 

However, you'll notice that there is only a single variable set. This works for all environments up until Production. This is because for Production, we have a "staging" slot. If this build was to run and deploy into staging, and it reads the pipeline variables, it will actually deploy into Production. 

 

I have asked previously if Pipeline variables can be used only with the staging slot, and was told no. As it is a single pipeline that deploys into both staging and production, the pipeline variables are shared. 

 

The next thought might be something like having two sets of pipeline variables. For example : 

 

AIO_RUNTIME_NAMESPACE = {ProductionAIO}

AIO_RUNTIME_NAMESPACE_STAGING = {StagingAIO}

However, that would require some logic within the POM file, and would also require the ability to know within the build step that we are deploying for Staging. I'm not sure how to achieve this. 

 

So realistically : 

- How can I detect (If it's possible) that I am deploying to the staging slot, via Adobe Sites Pipelines?
- How can I add logic to my POM file to pull a pipeline variable based on that detection? Is this possible? 

- How has anyone got this far with AEM Sites with SPA Components/SSR without running into this issue? Do they just not use the staging slot? 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello WadeGa,

 

Adobe provided separate explanation for Environment Variables and Pipeline Variables. I don't think proving this is really answering your original question. Here are the reasons:

-  pipeline variables are another environment variables for the build machine against the program/pipeline (accessing mechanism from pom will be the same)

- so far Adobe provides only one production pipeline (for stage and prod) per program

 

In such case,  doesn't matter you define/create pipeline variables or environment variables, its not gonna help you.

 

One probable way to address this issue, can be creating multiple programs (if you are allowed to do so by Adobe).  Create two programs (program-1 and program-2). Under program-1, create one prod pipeline for stage deployment, with in that you can create your pipeline variables for stage. Similarly configure program-2 for prod deployment.

 

Let me know if that makes sense or you have different opinion.

 

Thanks

 

View solution in original post

7 Replies

Avatar

Community Advisor

Before you look for the solution, you need to know that the code is build only once when we deploy in STAGE and PROD.

Firts it is build and then deploy to stage and then after approval prod.

 

So you can't build conditionally here.



Arun Patidar

Avatar

Level 2

The pipeline variables are used within the *deploy* to Adobe IO, not necessarily the compilation of the code. I'm unsure if it makes a difference. 

 

Either way, I'm using the Adobe AEM Archetype with SSR, with nothing else added, and I have this issue. 

Maybe a better question would be. How do existing customers, using the Adobe Archetype with SSR, provided by Adobe, deploy to production? Because I can't see how it's possible. 

Avatar

Community Advisor

Hello @WadeGa,

 

If you are using cloud manager to deploy your code, you can not depend on CM environment variable as you have a single machine/server to pick the variables from. Hence, you can not expect to set same variable with different value/data based on the environment (stage or prod) you are deploying to.

 

Since you have environment (stage/prod) specific configuration/properties, I would rather suggest you to move these properties in OSGi config, where you have runmode support. 

 

 

 

config.author.stage // file taking variables for stage author  
config.author.prod // file taking variables for prod author  

 

 

 Meaning you can define the properties as key/value pair within the files above, variable will be picked up based on the environment.

 

Thanks

 

Avatar

Level 2

Hi, 

 

That's actually incorrect (According to my understanding and Adobe support thus far).

 

Variables used within a pipeline are actually called Pipeline variables and are an entirely different concept to Environment Variables which are for runtime. You can read more here : https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-...

 

Because I am using the Adobe Archetype with SSR, that deploys to Adobe IO (Infact SSR is hosted on Adobe IO in general), this is most definitely a pipeline issue. I need to know which Adobe IO namespace to *deploy* to. This cannot be solved at runtime. 

Avatar

Community Advisor

Hello WadeGa,

 

From the document you shared pipeline variables are set as environment variable: 

silk_route11_1-1693557303073.png

 

If you find a way to have same variable (holding different data) in different name space in CM, please let me know. That would be interesting.

 

Thanks 

Avatar

Level 2

Sorry, that is incorrect. In that specific piece of text, they mean you can access it like an Environment Variable as in a env variable on windows, it is *NOT* the same as an AEM Environment Variable. 

 

To further illustrate this, here's the documentation clearly outlining that *IN ADDITION* to environment variables, there are pipeline variables. 

WadeGa_0-1693944352637.png

In addition, you set environment variables via the AIO command line like so : 

 

aio cloudmanager:set-environment-variables ENVIRONMENT_ID –variable MY_VAR1 “plaintext value”

And for pipeline variables it's an entirely different command : 

aio cloudmanager:set-pipeline-variables PIPELINEID --variable MY_CUSTOM_VARIABLE test

 

I've unmarked your answer as correct because it's not unfortunately not correct, and does not answer the original question. 

Avatar

Correct answer by
Community Advisor

Hello WadeGa,

 

Adobe provided separate explanation for Environment Variables and Pipeline Variables. I don't think proving this is really answering your original question. Here are the reasons:

-  pipeline variables are another environment variables for the build machine against the program/pipeline (accessing mechanism from pom will be the same)

- so far Adobe provides only one production pipeline (for stage and prod) per program

 

In such case,  doesn't matter you define/create pipeline variables or environment variables, its not gonna help you.

 

One probable way to address this issue, can be creating multiple programs (if you are allowed to do so by Adobe).  Create two programs (program-1 and program-2). Under program-1, create one prod pipeline for stage deployment, with in that you can create your pipeline variables for stage. Similarly configure program-2 for prod deployment.

 

Let me know if that makes sense or you have different opinion.

 

Thanks