Expand my Community achievements bar.

SOLVED

Web Tier Build Failing due to environment variable used in dispatcher

Avatar

Level 2

We have created environment variable named "ENV_TYPE" in cloud manager. When we are trying to use this variable in dispatcher code. The build is failing in code scan step. 

 

Code below which makes use of env_type variable in dispatcher.
Include /etc/httpd/conf.d/variables/org_$[env:ENV_TYPE].vars

 

Logs below from the error

processing configuration subfolder: conf.d
processing configuration subfolder: conf.dispatcher.d
validating via httpd -t in DEV environment type mode
httpd: Syntax error on line 357 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/000_load_env_vars.conf: Include/IncludeOptional: No matches for the wildcard 'org_$[env:ENV_TYPE].vars' in '/etc/httpd/conf.d/variables', failing
ERROR: '1 TEST_FAILURE '
at reportError(/usr/local/bin/lib-status.bash:198)
at validate_configuration(/usr/local/bin/validate-static.sh:198)
at runValidation(/usr/local/bin/validate-static.sh:242)
at status.track(/usr/local/bin/lib-status.bash:261)
at main(/usr/local/bin/validate-static.sh:245)
Reporting error to: '/mnt/shared/status-validation'
ERROR: '1 SCRIPT_ERROR Script command failed (see stack trace)'
at status.internal.handleError(/usr/local/bin/lib-status.bash:269)
at status.track(/usr/local/bin/lib-status.bash:269)
at main(/usr/local/bin/validate-static.sh:245)
Status file exists: '/mnt/shared/status-validation' assuming it is already saved in earlier step.
at status.internal.handleExit(/usr/local/bin/lib-status.bash:56) exited with code '1'

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@akash_mca2008 

 

Please try using 

${ENVIRONMENT_TYPE}

Details present here: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/conten...

 

 

Currently, the same Dispatcher configuration is applied to all environment on AEM as a Cloud Service. The runtime has an environment variable ENVIRONMENT_TYPE that contains the current run mode (development, stage, or production) and a “define”. The “define” can be ENVIRONMENT_DEV, ENVIRONMENT_STAGE, or ENVIRONMENT_PROD. In the Apache configuration, the variable can be used directly in an expression. Alternatively, the “define” can be used to build logic:


# Simple usage of the environment variable
ServerName ${ENVIRONMENT_TYPE}.company.com

# When more logic is required
<IfDefine ENVIRONMENT_STAGE>
  # These statements are for stage
  Define VIRTUALHOST stage.example.com
</IfDefine>
<IfDefine ENVIRONMENT_PROD>
  # These statements are for production
  Define VIRTUALHOST prod.example.com
</IfDefine>

 

To work with ENV_TYPE, please set in pipeline variables and use ${ENV_TYPE} as suggested by @arunpatidar  and @EstebanBustamante 


Aanchal Sikka

View solution in original post

8 Replies

Avatar

Level 2

Sorry, I should have mentioned this is for AEM as a cloud service.

Avatar

Community Advisor

Hi @akash_mca2008 
Ensure that the Dispatcher configuration file (000_load_env_vars.conf) is correctly using the org_$[env:ENV_TYPE].vars wildcard pattern and that the file org_$[env:ENV_TYPE].vars exists in the specified directory (/etc/httpd/conf.d/variables). and check the syntax of your Dispatcher configuration files. The error indicates a syntax issue on line 1 of 000_load_env_vars.conf. Verify that the configuration files are correctly formatted.
check below urls:
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-... 
https://experienceleague.adobe.com/docs/experience-manager-learn/ams/dispatcher/variables.html?lang=... 

Thanks.



Avatar

Community Advisor

Hi,

 

Your best option is to first test locally as the documentation suggests: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-... 

 

As per my understanding, you should use the variable in this format: ${var_name}. You can find more details here: here: https://techrevelhub.wordpress.com/2023/08/28/navigating-aem-dispatcher-setup-farm-file-resolution-a... 



Esteban Bustamante

Avatar

Community Advisor

HI @akash_mca2008

 

1. Check the value of the ENV_TYPE environment variable and make sure it is set correctly for your DEV environment. You can also use the Adobe I/O CLI to check the value of the environment variable by using the aio cloudmanager:list-pipeline-variables command2.

2. check startup argument - /etc/sysconfig/httpd
Ref - https://experienceleague.adobe.com/docs/experience-manager-learn/ams/dispatcher/variables.html?lang=...

3. Check the /etc/httpd/conf.d/variables folder and make sure there is a file named org_<ENV_TYPE>.vars that contains the environment variables for your DEV environment.

4. If the file does not exist, you can create it by using the Adobe I/O CLI to set the environment variable by using the aio cloudmanager:set-pipeline-variables command2. This command will create the file and make it available inside the build environment as an environment variable. You can then reference the variable from inside the pom.xml file or other build scripts.
5. If the file exists, but the name does not match the wildcard, you can rename it to match the expected format by using the Adobe I/O CLI to update the environment variable by using the aio cloudmanager:set-pipeline-variables command.

After you have fixed the file name and content, you can run the validation process again from the Cloud Manager UI or the Adobe I/O CLI.


https://experienceleague.adobe.com/docs/experience-manager-learn/ams/dispatcher/variables.html?lang=...

Avatar

Community Advisor

HI @Nitin_laad 
 aio cloudmanager:set-pipeline-variables this will set the pipeline variables but environment variables.

To set environment variables use 

 

aio cloudmanager:environment:set-variables ENVIRONMENTID --variable=MY_VAR1 “plaintext value” 

 

https://github.com/adobe/aio-cli-plugin-cloudmanager?tab=readme-ov-file#aio-cloudmanagerenvironments... 



Arun Patidar

Avatar

Community Advisor

Thanks @arunpatidar Thanks for the correction. Copy-pasting can be confusing at times.

Avatar

Correct answer by
Community Advisor

@akash_mca2008 

 

Please try using 

${ENVIRONMENT_TYPE}

Details present here: https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/conten...

 

 

Currently, the same Dispatcher configuration is applied to all environment on AEM as a Cloud Service. The runtime has an environment variable ENVIRONMENT_TYPE that contains the current run mode (development, stage, or production) and a “define”. The “define” can be ENVIRONMENT_DEV, ENVIRONMENT_STAGE, or ENVIRONMENT_PROD. In the Apache configuration, the variable can be used directly in an expression. Alternatively, the “define” can be used to build logic:


# Simple usage of the environment variable
ServerName ${ENVIRONMENT_TYPE}.company.com

# When more logic is required
<IfDefine ENVIRONMENT_STAGE>
  # These statements are for stage
  Define VIRTUALHOST stage.example.com
</IfDefine>
<IfDefine ENVIRONMENT_PROD>
  # These statements are for production
  Define VIRTUALHOST prod.example.com
</IfDefine>

 

To work with ENV_TYPE, please set in pipeline variables and use ${ENV_TYPE} as suggested by @arunpatidar  and @EstebanBustamante 


Aanchal Sikka