How to get environment information in Mule - mule

I need to put some production specific behavior in mule-config.xml. Is there a way to get environment info in mule?

You can access all system properties via MEL. But I would rather suggest you modularize your configuration in several files (say: common-config.xml, test-config.xml, prod-config.xml) and load the right files at Mule startup based on the environment.

And also you can create properties file for each environment and access it inside mule config file.

You can create xml file with all the configurations and import/load the file into mule project

In your Mule configuration file (src/main/app/app-config-file.xml), you can add the following line:
<context:property-placeholder location="${environment.name}.properties" />
${environment.name} must be a system environment variable. You need to make sure the system where you are deploying your app contains that variable. I think you can also specify it in the Maven build, if you are using Maven (clean install -Denvironment.name=test). You can try.
To test locally, right click on your project, select run as, select run configurations, click on Environment tab, add your variable "environment.name" and the value "local" (without quotation marks) and make sure your local.properties file exists in a location added to the build path. It can be src/main/app for example or in the resources folder.

MEL has some context objects like server, mule ,application using these you can get the envinformation from #[server.env] for more info refer
https://docs.mulesoft.com/mule-user-guide/v/3.6/mule-expression-language-basic-syntax

You can use different mule properties file like Mule-dev.properties , mule-test.properties.
In global elements add a property placeholder :
In mule-app.properties define env= test or dev depending on the env value which you want to use.
Clean the project and deploy. Sometimes it is not able to read the env specific properties. Cleaning the project solves this issue.

You can add a properties file in you project and refer it from property place holder. it is better to add environment value in mule-app.properties file ehich is in /src/main/app

you can have one variable like mule.env in this mule-app.properties and send value to this Property as DEV,QA,UAT,PROD from cloudhub properties and create different properties file in mule/src/app main resources then use Properties placeholder to configure this property file and send the value of mule-env dynamically from cloudhub

Typically the way this is done is to delcare a property bean in which you set the environment specific value like PROD,QA,DEV or local. This environment specific value is set in mule-app.properties like mule.env=local, This needs to be set to the environment we are trying to deploy it and the API picks up the right properties file.

Related

I want to pass my SBT build version as dynamic parameter to a parameter in yaml file. How to do it?

Have a scenario where my yaml file has a config for application. I am passing "s3://[Shelfscrpti folder name]/1.1.5 SNAPSOT
Need help to get the snapshot part alone as a dynamic parameter.

Using path variable in intellij maven run configuration

I'm trying to set up and share maven run configurations in my team and I have this problem. Every team member has different project path. I would like to use path variable in order to define working directory for maven run config. Looks like IntelliJ doesn't evaluate this path variable. Any ideas how to solve this problem?
Error:"the working directory '$MODULE_DIR$' does not exist". "$MODULE_DIR$" is default IntelliJ path variable.
You do not need to do anything. Just use the default value which is a real path to the module inside your project. IDE will automatically use the Path Variable for the Run Configuration xml file.
Note that path variables can not be used in the UI for specifying paths. IDE automatically substitutes them when you use real paths.

How to set an api path during the build process of a vue application based on environment variable?

I am wondering if there is a way to change a 'root path' for my site's api which is a string value of a variable at build time in a vue application. I would like the value of my api path to be read in during the build process and set. This functionality exists in angular, and I am wondering if it exists in vue. I have checked the docs and do not see anything similar. This blog describes the functionality that I am after in angular. If there is nothing similar how does one change the root path of an api from for example 'localhost:8080' to 'example.mysite.com' at build time so that the right path is set when building/deploying to production and not needed to be changed manually? Thanks for any help!
You could set it in an environment variable during the build and access it via process.env.MY_VARIABLE.
During development you would use a package like https://www.npmjs.com/package/dotenv and have a .env file with your environment variables but in production you would set it in your CI or build script.
Bare in mind if this is browser based then you will need to replace
process.env references with the explicit values which you can do with most bundlers.

Extracting MSDeploy Zip package using variables

I’m setting up an automated build in VSTS that will FTP the published files to my server.
I have this working but the way I’ve achieved it, I feel is hacky and non-sustainable.
the process as you can see from the screenshots will publish the artefact which consists of a readme, cmd file and a zip containing all my publish files and then I extract the ZIP with the very explicit location below.
$(Build.ArtifactStagingDirectory)\temp\Content\d_C\a\1\s\IntermittentBug\IntermittentBug\obj\Release_EukHosts\Package\PackageTmp
I’m using a hosted build server in VSTS but as the path contains
d_C\a\1\s\
I assume this will change in time. What I need is a variable to cater for this path so it will always succeed.
How can I update this to make it more efficient and sustainable?
First, as jessehouwing said that the variable is called Build.SourcesDirectory.
Regarding the path structure, the simple way is specifying /p:PackageTempRootDir="" msbuild argument in Visual Studio Build task to remove the source path structure, then the path will be like Content\D_C\PackageTmp.
On the other hand, you also can publish the web app through File System mode.
This variable is caught in a predefined variable called Build.SourcesDirectory. see the complete list of predefined variables here.
In your batch or powershell scripts this variable is available as a environment variable called %BUILD_SOURCESDIRECTORY% / $env:BUILD_SOURCESDIRECTORY.

IntelliJ & Global Config Files

I've been searching for a solution but I can't find one.
I have a global configuration directory in my IntelliJ workspace. I also have several dozen modules. I would like each module to automatically include the global config directory in its path when I run or test a class.
Is there anyway to do this within IntelliJ? I don't think I should need to edit the configuration for each "Run/Debug" config to include the directory.
You'll want to set it in the Defaults for the type of Run or Debug Configuration that you are using.
For example, if I always want a Java Application to have the VM Option -XPutYourThingyHere, then I could go to Edit Configurations, Defaults, Application, and put -XPutYourThingyHere in the VM Options box. Then all new Applications that I run will have that option.