Jenkins agent incorrect PATH environment variable - jenkins

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.

Related

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.

Setting environment variables for Jenkins slaves

New to jenkins and looking to create a job. I need to use the IP of my Jenkins Instance in part of my Java Code. Is there an existing environment variable that I can use or do I have to add one myself? If so, how exactly can I do this? The slaves are ec2 instances. I looked at some similar questions posted here but it seems they are talking about the master rather than the slaves. Thanks!
EDIT: To confirm, external requests will be sent to the IP that I set in my Java code
I do not think there is any such environment variable in the default list of jenkins Environment variables.
One way to set IP as environment variable on a slave is:
Go to the slaves configuration page
Under "Node properties" there is a section called "Environment Variables"
Add a new Environment variable, e.g. IP_ADDRESS with value = the ip of that slave.
You should be able to access it from jenkins job, just like any other environment variable. e.g. in a Shell build step ${IP_ADDRESS}

using environment variables from a jenkins slave

i have a little problem.
Our setup consists of 1 Master Jenkins and 2 Slaves, both Slaves use a different SVN Location String, which we saved in an Environment Variable... but both of them start the same .dll for a Test - Now my problem is that when i use %SVN_Location% that it takes the Environment Variables from the computer i run the build (the master).
So my question is there a way to tell him somehow to execute the %SVN_Location% not on the computer where the build starts, but on the computer where the slave runs
Use EnvInject to record the value you want to file
Use Copy To Slave to move the file to slave
User EnvInject on slave to load value to environment variables, before the SCM step
I managed it myself after some more Research to actually get the Environment Variable directly from the Slave and use it as a Parameter for the Master Node.
With the Plugin Dynamic Parameter by using a Dynamic Parameter and the Default Value Script: System.getenv("SVN_Location_TP1") and the checkbox Remote Script checked.
When starting the build with parameters now, it automatically loads via remote script the Environment Variable from the slave and uses it as a parameter for the jenkins execution, which can be used with %SVN_Location_TP1% (in my example)

Override system environment in node config

I am trying to override TMPDIR for builds kicked off on one of my nodes.
I've added a new value in the node properties environment variables:
But when I run my job, TMPDIR is still set to the system value. ZIG does get set, however:
# Output from job running `env`
TMPDIR=/var/folders/nf/p0pz9cv93wz8m314wyk3yp_h0000gn/T/
ZIG=Zag
The same thing happens if I add the environment settings to the Jenkins master config. I can successfully use the EnvInject Plugin to change it on each job, but we have a number of jobs and I would really prefer that it be a node configuration (the node has a dedicated build drive).
How can I override TMPDIR for all builds launched on this node?
I am using Jenkins 1.624 on OS X Yosemite 10.10.5.
I had the EnvInject plugin installed, which was preventing the environment variables from being overridden (even though I wasn't using it, and it didn't work when I turned it on anyway).
I uninstalled that plugin and now my problem is gone.

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