Pre Configured Environment variables in Jenkins - jenkins

I am running Jenkins though the docker image.
I want my Jenkins Installation to come up with few pre configured enviroment variables.
Is there any way I can copy some of my environment variables, so that when I bring my jenkins up, it should come with these pre-configured environment variables ?
Or
Where are the environment variables stored in the Jenkins installation ?
TIA.

Related

What is the best way to use user environment in Jenkins?

I have Jenkins set up on MacOS and want to execute commands that are installed on my user (e.g. Ruby, cucumber). Unfortunately, Jenkins does not use Environment vars of current user, so all installed programs does not work correctly (such as Ruby, and its dependencies).
For example, for Ruby and Cucumber I have to manually specify all necessary envs vars, including the $PATH
Is there a correct way to use current user environment without manual ENV set up or EnvInject plugin or the environment {} block in jenkinsfile?
I want that all vars user environment and system environment variables would be accessible in Jenkins job without manual updating of environment every time I install new package

Jenkins slave override environment variable set by master when execute multibranch pipeline job

I have setup Jenkins with a master node running Ubuntu and a slave node. Currently Jenkins use to build Android app (master and slave have different ANDROID_SDK_ROOT environment variables).
For slave I have configured environment variables as below:
The free style project run OK and the slave able to pickup the environment variable. A problem happens when I run multibranch pipeline job. It seems the job cannot pickup the environment variable always show error:
SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at
What is the root cause and how to make multibranch pipeline able to pick up correct environment variable?
Updated: I detect the problem because slave cannot override environment variable value set by master. But I don't know how to make slave able to override environment variable set by master.

Jenkins agent incorrect PATH environment variable

I'm using a remote agent/slave to build my project in Jenkins via SSH.
Although the correct PATH environment variable is available when SSH'ing to it with the same user, it's not available when Jenkins tries to use the agent for building.
With the pipelines DSL, I was able to add it to my environment at runtime.
environment {
PATH = "/usr/local/bin:$PATH"
}
But I want this location in the PATH variable at all time, without this configuration. Any pointers on how to configure this for my agent/slave; whether it is in the jenkins node configuration or on the machine itself?
Just for anybody who is having the same issue.
When adding a new node in Jenkins, the master caches the environment variables of this node, but doesn't update it afterwards, to avoid breaking the configuration.
If you update the environment variables on the node itself, this changes won't be available for builds from the Jenkins master. You have to re-add the node or add environment variables in the configuration of the node.

Pre-configured Environment Variable in Jenkins

I am running Jenkins though the docker image.
I want my Jenkins Installation to come up with few pre configured enviroment variables.
Is there any way I can copy some of my environment variables, so that when I bring my jenkins up, it should come with these pre-configured environment variables ?
TIA.
A list of available environment variables is available here: https://hub.docker.com/_/jenkins/
Update
If you want to add your own environment variables you need to build your own jenkins image. You can do this by extending an existing image or modify the official docker build project provided by jenkins on GitHub.
Docker has a nice tutorial on how to build images here.
In this specific case you need to modify the docker entrypoint file to retrieve and replace the environment variables where needed. For jenkins, the docker entrypoint file is located in /usr/local/bin/jenkins.sh.

How to make Jenkins use already existing environment variables set on a slave node?

I am making use of a batch script that is supposed to run on a slave node, which makes use of Sahi. The environment variable for Sahi is set as 'SAHI_HOME' on the node.
When I run the batch I figure out, it is not able to locate Sahi classes.
How do I enforce Jenkins to make use of environment variables set on the slave? I mean is there any way to fetch environment variables set on a slave node?
We got around this issue by installing and updating Sahi automatically. There is a nice Jenkins Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin
You just need to place a Sahi Zip somewhere for Jenkis to access. The custom tool plugin automatically unpacks archives and creates a toolname_HOME environment variable.
Just name your tool SAHI and you have Sahi and $SAHI_HOME on every job and node you need.
Regards
Wormi
I ran into a similar issue with my AIX slaves. The issue is that the .profile file is not executed when a non-interactive shell is started. Therefore, you have several options.
Make sure that the environment variable is set in the environment file (in AIX, I can set the ENV variable to a filename that will be executed for both interactive and non-interactive shells.) I think the .kshrc file might qualify too.
Set the environment variable in the node configuration
set the environment variable in the master configuration
set the environment variable in the job (needs env inject plugin)
set the environment variable explicitly in the bash script

Resources