Run first command on Jenkins Server and second command on the slave? - jenkins

I have a requirement like I want to execute a script first on the Jenkins Server and the second script on the slave. Is it possible?
The server is up on a Ubuntu machine - the first script will setup the jobs html log file and the second script will run the actual test and stores the log at the end. I need to pass the env variables set by Jenkins to the second script. How can it be done?
Also, Is it possible to send the env variables set in Jenkins Server during run time to the slave and set the same in the slave?

Related

How to run a Jenkins job in other servers?

I am using digital ocean droplet.My scenarios is: I have Jenkins installed on my one server, in which I have configured the job.I want to run that job on to another server.How to achieve that?(How my Jenkins will able to ssh to another server)
If you want to execute a single command on another server - use ssh to invoke command as a build step.
If you want to run a complex job - you should configure target server as a slave and point your job to run on a specific node(slave).
Configuring slave is pretty easy, take a look at the following articles
https://wiki.jenkins.io/display/JENKINS/Distributed+builds
https://wiki.jenkins.io/display/JENKINS/SSH+Slaves+plugin

Jenkins command in Execute shell cannot read environment variables from /etc/profile.d/xx.sh

When I execute a shell script in Jenkins Execute shell build step, the pre-defined environment variables in /etc/profile.d/xx.sh does not work.
I need help! Thx!
Bash reads the profile only for interactive login shells, or if it is started with the --login option. It will not be read when performing a build step or when connecting a slave.
The easiest workaround will be to explicitly source the profile by adding a
. /etc/profile
in the beginning of your build step.
This will then also immediately reflect any changes, without need to restart the master or to reconnect the slave (depending on where the build is running).

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)

Jenkins Jobs are not loading while starting it from CLI

I have setup a lot of jobs while Jenkins is running as windows service.When i try to start Jenkins from command line , none of the jobs are showing up.
Can some one let me know how to make sure all jobs are loaded when i start Jenkins from CLI on windows machine.
Make sure you have the same Jenkins home directory when you run it from CLI.
You can use JENKINS_HOME variable to control that:
set JENKINS_HOME=C:/myJenkins
java -jar jenkins.war

launch-slave script

according to the jenkins wiki
/var/jenkins/bin/launch-slave is a shell script that Jenkins uses to execute jobs remotely. This shell script sets up PATH and a few other things before launching slave.jar. Below is a very simple example script
I'm running jenkins as JNLP and don't have a /bin, so I'm not sure where should i put this file
Run Jenkins 'headlessly', not via a browser:
java -jar slave.jar -jnlpUrl http://[jenkins_server]/computer/[slave-name]/slave-agent.jnlp
Write a script containing that command and add whatever else you want before it, including setting the new PATH.
You can also specify environment variables (or 'key-value pairs') in the slave node configuration. Navigate to http://[jenkins_server]/computer/[slave-name]/configure and check off 'Environment Variables' check-box.
The script on Jenkins wiki you refer to is meant as an example for those who want to use slaves of type "Launch slave by executing a command on master". If you are using JNLP type slaves, then you don't need this script.
What you need to do is log onto the slave machine, open the web browser to your Jenkins, navigate to the page of your slave and hit the orange button. Or use one of the command lines on the page to run the slave.

Resources