How can I retrieve environment variables(Jenkins) in java - java

I'm setting some environment variables by some windows batch commands in the pre-build steps for a Jenkins build. I need to use these variables for a few java selenium test cases which will run during as part of the build.
set HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS = %WORKSPACE%\selenium_input_files\Key_Features\en_US
I have tried to retrieve these environment variable values by using System.getEnv(HD_KF_TC_IN_LOOK_UP_KET_FEATURE_XLS) commands. But this is not working as the values for these variables is always NULL.
Please let me know where I'm I going wrong?

As indicated in my comment, I do not completely understand your setup. In general, however, environment variables set in one Jenkins build step do not propagate outside of it and can't be accessed from other build steps. You need to use EnvInject plugin to achieve that.

Related

IntelliJ IDEA does not see my environment variables

I've configured an environment variable in ~/.bashrc as well as ~/.profile.
When I run my application via IDEA's Gradle Configuration, my environment variable is apparently not available. E.g. I am referencing this variable within application.yml, but the default value is being used instead. Running Gradle from the command line correctly picks up my variable.
How can I configure IDEA to load this environment variable in a global way, so I don't have to manually add it to every project where I need it (~20 projects)?
Note: running on Manjaro Linux v18.
It turns out IDEA will pick up environment variables if you define them either in e.g. /etc/environment or /etc/profileor if you use ZSH,~/.zshrc`.
After setting variables, you to execute source ~/.bashrc and source profile to update and execute the file contents.
# josh-m I ran into the same problem in my IntelliJ IDEA setup with Maven.
In the end, I continued to keep the settings on each project, as there were not many, but when I studied the problem I found this IntelliJ support link:
https://youtrack.jetbrains.com/issue/IDEA-141832
At least at that time, this functionality was not available in IntelliJ directly, although the following plugin, mentioned in the comments of the support article, could perhaps be of some help:
https://plugins.jetbrains.com/plugin/7861-envfile/
launchctl setenv HADOOP_VERSION 3.1.1.7.2.8.0-SNAPSHOT
Execute in this way to set your environment variables in MacOS for them to be used by other applications.
After that restart your IDE.

Cannot find packages related to JUnit when compiling test code

Trying to get JUnit working on my computer. I'm using windows but I have also installed git bash as well (don't know if that makes a difference).
Anyway I've followed this tutorial linked below:
https://www.tutorialspoint.com/junit/junit_environment_setup.htm
I'm trying to set the environment variables manually on windows but the instructions above aren't working for me.
https://imgur.com/a/NaqFiue
^Here is a photo of my user variables after making the changes in the tutorial. On the above tutorial it says to link the JDK to a variable called JAVA_HOME, and mine worked perfectly with Path as seen in the image but it did not work with JAVA_HOME.
I'm honestly so confused, lost and frustrated. Any help would be appreciated.
Why does your classpath settings has so many semi-colons?
You haven't set JAVA_HOME yet. Usually it's necessary to set
JAVA_HOME, as it's assumed by most Java libraries. You can set the
Java path by %JAVA_HOME%\bin.
What is your commmand line to run Junit? Have you compiled
successfully?
JUnit has its own Getting Started. Can you try it instead of the tutorial that you used. It does not rely on environment variables. Therefore it should be easier to run it.

How to identify whether TestNG test is running on Jenkins or not?

Is there any jenkins property which can i access in my java code to identify that code is running on jenkins ? I have around 1000 of test cases running on different jenkins CI, which is managed by different teams. I dont want to set any manual flag or string properties in each of my jenkins build, There should be some property which can be use to identify this ?
You can take a look at this page which calls out all the environment variables that are exposed by Jenkins. So you could have your Java code query any of these environment variables to determine if the java is being run in a Jenkins environment or is it being run from a dev box or an IDE even.

how to pass my choice parameter value to ant in jenkins

Hi Guys and thank you in advance, I am new two jenkins and I have a test automation project that i usually run it on different environment, now here is how my current project look like in jenkins
QA must to point to a specific configuration file example:
projectName/config/liveEnvironment.text
and the suites must point to the suite to be triggered:
projectName/suites/IAsuite.xml
and here is my ant command:
now what should the variable format look like in the ant, and how can it get it from the choice parameters.
thank you
The parameters are set as environment variables.
In other words you should be able to call them with the normal syntax $variable_name

start code from eclipse plugin with own environment variables

What i already have:
Using eclipse keppler i am creating an eclipse plugin that is to work under linux, windows and mac.
I am trying to wrap some existing java code into this eclipse plugin. This works fine. The execution of the wrapped code can be started by clicking a button in the plugin ui. The wrapped code uses some environment variables. When these are set as environment variables and eclipse is then started the variables are found and used.
What i would like to do:
I would like to set the required environment variables in some textfields in the plugin ui and then start the execution of the wrapped code which should then use the variables form the textfields, so that i no longer need to set them as environment variables before starting eclipse. This would obviously be more flexible.
This feature is used by the eclipse ide itself when starting a run/debug-process. For these processes the environment variables can be set. This is the mechanism i would like to use.
My questions:
How is it possible to start a process from an eclipse plugin and provide it with a set environment variables that are set in the plugin ui?
Is it necessary to use ProcessBuilder or Runtime.exec() or is there some java-only solution?
Is the only way to find an answer to search through the eclipse souce code?
How is it possible to start a process from an eclipse plugin and provide it with a set environment variables that are set in the plugin ui?
Get the env variable names and values from your plugin UI.
Use ProcessBuilder or Runtime.exec() to launch a new (external) process with the appropriate environment variables.
(The 2nd step is the same as what you would do if you weren't using Eclipse.)
There may also be an Eclipse-specific way of doing this, but underneath the hood that will have to use ProcessBuilder or Runtime.exec().
Is it necessary to use ProcessBuilder or Runtime.exec() or is there some java-only solution?
If you want to run the Java code as a separate process, then at some level you have to use ProcessBuilder or Runtime.exec(). Conversely, while it is possible to run a Java application in "the current JVM", you won't be able to change the environment variable settings for the current application. (The Map you get from System.getEnv() is documented as "not modifiable".)
(I'm not sure what you mean by "java only". You could argue that one JVM launching another using ProcessBuilder or Runtime.exec() is "java only".)
Is the only way to find an answer to search through the eclipse souce code?
No. You could also find the answer by reading the javadocs ... like I just did :-)

Categories

Resources