how to change config server uri dynamically using OS environment - spring-boot

I have a spring config server and spring config client. In client I have set spring.cloud.config.uri to http://localhost:8888 but I want to change it to some other uri say http://example.com:8888 in windows using OS environment with setx. so I ran
setx spring.cloud.config.uri "http://example.com:8888"
but when I run my spring config client it's still trying to read from localhost . As per this link my spring.cloud.config.uri in bootstrap.yml should get override by what i set with OS environment but it didn't. Please let me know what I am doing wrong here.

setx
setx adds the variable but doesn't make it available in the current shell (as explained here):
setx modifies the value permenantly, which affects all future shells,
but does not modify the environment of the shells already running. You
have to exit the shell and reopen it before the change will be
available, but the value will remain modified until you change it
again.
Just make sure you are runnning from a newly opened shell window.
I suggest you use set spring.cloud.config.uri=http://example.com:8888 just for the sake of testing.
Check if the environment variable is present
You may add the following as the very first line your main method:
System.out.println(System.getenv("spring.cloud.config.uri"));
System.out.println(System.getenv("SPRING_CLOUD_CONFIG_URI"));
Variable name with underscore
Windows supports environment variables with dots, so it should be ok for you. This isnt the case for pretty much all the other OS. Just so you know, spring supports variable name with underscores (as explained in the link you provided):
If you use environment variables rather than system properties, most
operating systems disallow period-separated key names, but you can use
underscores instead (e.g. SPRING_CONFIG_NAME instead of
spring.config.name).

Related

How to enable NetBeans 15 for Mac honour the system environment variables with Gradle builds

I have recently started to use GitHub Packages to distribute our shared libraries internally and have retrospectively changed the Gradle build configuration to use credentials based on system environment variables, rather than hard-coded e.g.
repositories {
mavenLocal() // only use when testing -SNAPSHOT locally
mavenCentral() // third-parties
maven { // our-library
name = "MyLibrary"
url = "https://maven.pkg.github.com/MyCompany/mylibrary"
credentials {
username = project.findProperty("git_username") ?: System.getenv("git_username")
password = project.findProperty("git_token") ?: System.getenv("git_token")
}
}
}
Unfortunately no matter how many environment variables I changed, whether in ~/.zshrc or .zshenv or .bash_profile or /etc/launchd.conf the build was indicating that the credentials were prohibited, or more accurately were resolved as nul.
Each time I changed a config I also ran the appropriate source to ensure it was active, I even resorted to rebooting, just in case.
The environment variable would always show in the terminal confirming the environment variable was always set up correctly, e.g. echo $git_username or printenv yielded the environment variable and expected sensitive token.
After a lot of experimenting and with the help of a colleague we determined that launching NetBeans 15 from the dock wasn't helping, so instead we also added the following line to ~/.zshrc
alias netbeans="/Applications/NetBeans/Apache\ NetBeans\ 15.app/Contents/MacOS/netbeans &"
But now to launch NetBeans I can't use the dock icon, but manually launch the terminal and then type
netbeans
Here's the new lines added to ~/.zshrc
#
# RW - For GitHub Package access
#
export git_username=NotApplicableUsesToken
export git_token=redacted1
export git_publish_username=NotApplicableUsesToken
export git_publish_token=redacted2
#
# RW - So Netbeans launches and honours the environment variables above
#
alias netbeans="/Applications/NetBeans/Apache\ NetBeans\ 15.app/Contents/MacOS/netbeans &"
My question is, why didn't NetBeans when launched from the dock discover the environment variables? How should I configure NetBeans to pickup the environment variables without this workaround?
The Aqua GUI doesn't read any of the shell configuration files, e.g. .bash_profile, .bashrc, .login, .profile, .zprofile, or .zshrc. You were correct to start looking at launchd. Unfortunately /etc/launchd.conf is no longer supported and the file is not read.
Apple's Runtime Configuration Guidelines in the Environment Variables section states:
There are two ways to make environment variables available to an application. The first is to define the variables in a Terminal session and then launch the application from the same session. ...
The second way to associate environment variables with an application is to include the LSEnvironment key in the application’s information property list file. ...
Editing an application's plist doesn't seem like the best idea and your changes may be lost when the application is updated.
There is a third approach.
launchctl has setenv, unsetenv, and getenv sub-commands for managing environment variables. However the environment variables are not persisted across launchd instances.
It seems that a common approach is to create an agent job .plist in ~/Library/LaunchAgents that runs at user login to macOS that will execute launchctl setenv to set the environment variables that should be available to applications launched from the dock. There are discussions at "Set systemwide variable with /etc/launchd.conf does not work in 10.10" and "Environment variables for GUI apps" that point to resources for this approach. You may also want to see Creating Launch Daemons and Agents.
I haven't tested or tried this approach myself.

Jmeter_home environment variable is not defined correctly in Jenkins only ,works fine with cmd prompt

I am trying to integrate jmeter with Jenkins and when I try to execute getting jmeter_home env variable, is not defined correctly. It works perfectly when try to execute through the command prompt.
Tried multiple options of setting jmeter_home in Jenkins config global as ~/.jmeter.
Changing jmeter path in system and through a couple of options but no luck.
The environment variable name is case-sensitive, it needs to be JMETER_HOME
Tilda resolves to $HOME environment variable in shell, it might be the case it isn't set so in that case you might want to use full path or check your OS configuration
In general as per JMETER_HOME variable description
(Optional) May point to your JMeter install dir. If empty
it will be set relativ to this script.
So you don't have to pass it, JMeter will "guess" its home from the jmeter starup script location
Also remember that you can always launch JMeter .jar file directly as:
java -jar /path/to/ApacheJMeter.jar
And last but not the least you may find Continuous Integration 101: How to Run JMeter With Jenkins article useful

JMETER_HOME environment variable is not defined

I tried to execute JMeter 4.0 from the command prompt in Windows 7.
I got the following error during execution:
The JMETER_HOME environment variable is not defined correctly This
environment variable is needed to run this program
I set C:\apache-jmeter-4.0\bin to JMETER_HOME variable, but the problem remains
I can start JMeter with its jar file.
I use jdk1.8.0_162 and set JAVA_HOME environment variable correctly.
You should set JMETER_HOME to main JMeter directory as C:\apache-jmeter-4.0
Also don't set JMeter directory to JAVA_HOME variable (should hold Java installation path)
Ensure you have installed Java and JMETER Gui works fine first.
Then,
At User Variables add JMETER_HOME followed by D:\Jmeter (Where Jmeter is installed)
Next select Path in User variables and add D:\Jmeter\bin(Where Jmeter bin path is)
Save and restart cmd.
P.S: This is for Windows solution
First ensure you've Java installed
Second you need to ensure the working directory of your call is the JMeter installation directory.
Assumption your JMeter installation is located under:
C:\Program Files (x86)\apache-jmeter-4.0
then you need to set this as working directory.
As you can read in the jmeter.bat file itself:
JMETER_HOME - installation directory. Will be guessed from location of jmeter.bat
This might sound obvious, but I'm getting this error on machines that don't have Java installed. Of course, though a better message might have been nice!
Easiest way:
just delete the JMETER_HOME environment variable, run jmeter.bat and variable will be added automatically.
Asually a wrong JMETER_HOME entry causes this. make sure you have JMETER_HOME pointed to jmeter folder not inside bin directory. For example ,from my local windows i am able to see this thie environment variable
Type : echo %JMETER_HOME%
For me, setting the Windows environment variable didn't help. Instead it worked when I set the variable at the command line (using the root folder of jmeter).
Like this:
SET JMETER_HOME=C:\apache-jmeter-4.0
ensure java is installed and can check with java —version
assuming the path jmeter installed is C:\apache-jmeter-5.3
add the user variable
press new
add Jmeter variable name as JMETER_HOME
variable value as: C:\apache-jmeter-5.3
add the path
look for Path system variable and press edit
edit it to have C:\apache-jmeter-5.3\bin
it doesnt have Path(very unlikely), than press new and add variable name as path and value as C:\apache-jmeter-5.3\bin
restart cmd and type jmeter should do the job.
One reason for getting this error is to have JMETER_HOME variable defined in the environment variables but pointing to the wrong location. I had this problem due to previous installation.
You don't need to set JMETER_HOME path explicitly under user variables, just add/change under system variables under path variable as your bin path. If you already have earlier version of JMeter just append with latest version. Path looks like : C:\XXX\apache-jmeter-4.0\bin

Using environmental variable in rabbitmq.conf file

I am using RabbitMQ in windows environment. I am using RabbitMQ with ssl configuration.
My requirement is to use environment variable in the rabbitmq.conf file to read SSL certificates. I have used it as below,
{cacertfile, "${MY_HOME}/config/SSLCertificates/testca/cacert.pem"
The above usage of environmental variable doesnt work. Can any one of you please help me in correct usage of environmental variable.
Try adding your variables to file rabbitmq-env.bat from the docs that's the location in windows:
If rabbitmq-env.conf doesn't exist, it can be created manually in the location, specified by the RABBITMQ_CONF_ENV_FILE variable. On Windows systems, it is named rabbitmq-env.bat.
Also, you may need to use %% instead of ${} since you are in windows.
From the windows section
If you need to customise names, ports, locations, it is easiest to configure environment variables in the Windows dialogue: Start > Settings > Control Panel > System > Advanced > Environment Variables.
So after defining your environments, try this:
...
{cacertfile, "%YOURVAR%\path\to\cacert.pem"}
...
Windows: %APPDATA%\RabbitMQ

nativescript installation don't work everywhere

i'm beginer in nativescript,i have correctly install ANDROID_HOME environment variable which return my sdk path after echo $ANDROID_HOME but despite this it return me The ANDROID_HOME environment variable is not set or it points to a non-existent directory. You will not be able to perform any build-related operations for Android
but if i put my project in the same directory with sdk directory it return me
Cannot resolve the specified connected device by the provided index or identifier. To list currently connected devices and verify that the specified index or identifier exists, run 'tns device'
I also notice that after each computer restarting environment variable disappear and i must resume a same process , i have edit .profile file, .bashrc file and zshrc file for environnement variable i have a same result
please tell me what wrong ... thank in advance
my ~./bashrc file
export ANDROID_HOME=/home/user/Android/Sdk
export PATH=$PATH:/home/user/Android/Sdk/tools
export PATH=$PATH:/home/user/Android/Sdk/platform-tools
export LD_LIBRARY_PATH=/home/user/Android/Sdk/emulator/lib64
In /home/user/Android/Sdk should be tools and platform-tools folders.
That's enough for me. (Linux Mint 18)
Maybe this information will be useful to someone:
Linux environment variables configuration files
.bashrc
This file is a variable for a particular user. It is loaded every time the user creates a terminal session, that is, in other words, opens a new terminal. All the environment variables created in this file take effect every time a new terminal session begins.
.bash_profile
These variables take effect every time the user connects remotely over SSH. If this file is missing the system will look for .bash_login or .profile.
/etc/environment
This file is for creating, editing and deleting any environment variables at the system level. The environment variables created in this file are available for the entire system, for each user and even for a remote connection.
/etc/bash.bashrc
System bashrc. This file is executed for each user, each time he creates a new terminal session. This only works for local users, when connected through the Internet, such variables will not be visible.
/etc/profile
System file profile. All variables from this file are accessible to any user on the system only if he entered remotely. But they will not be available when creating a local terminal session, that is, if you just open the terminal.
All the Linux environment variables created with these files can be deleted only by removing them from there. Only after each change, you need to either log out and log in, or execute this command:
$ source file_name
So, the environment variable can be of three types:
Local environment variables
These variables are defined only for the current session. They will be irretrievably erased after the session is completed, whether it is remote access or terminal emulator. They are not stored in any files, but are created and deleted using special commands.
Custom shell variables
These shell variables in Linux are defined for a specific user and are loaded each time it logs in using the local terminal, or it is remotely connected. Such variables are usually stored in configuration files: .bashrc, .bash_profile, .bash_login, .profile or in other files located in the user's directory.
System environment variables
These variables are available throughout the system, for all users. They are loaded when the system starts from the system configuration files: / etc / environment, / etc / profile, /etc/profile.d/ /etc/bash.bashrc.
If you are using nvm to manage different nodejs version, then try disabling nvm and using only one global nodejs version.
Regarding the environment variables that are being volatile, make sure that you track down the proper profile file that is being parse and place your changes there.
It would help if you can be more specific about your current platform. Then, people will be able to respond with more precision.
hi i solve my problem by adding in profile file environnement variable
export ANDROID_HOME=~/Android/Sdk
export ANDROID_HOME=~/Android/Sdk/tools
export ANDROID_HOME=~/Android/Sdk/platforms-tools
then i erased all path generate by all commands line entries from my terminal in .bashrc file(i think that it was that the problem source) . finally it work well thanks a lot to everybody for your helps

Resources