We have a build job that runs on a Jenkins slave node (Windows machine).
The job uses environment variables defined in Windows on the slave.
Now, we had to change the values of some of the environment variables on the slave.
When we call 'set' on the slave machine it shows the changed values correctly.
But when we start the build job on Jenkins and call 'set' there (Windows Batch Command) then the log still shows the old values of the environment variables!
The same wrong values we see when we go to 'Jenkins' > 'Nodes' > '' > 'System Information'.
Do you know what causes the problem and how it can be fixed?
Thank you.
Environment variables are propagated to child environments at the time of the child environment creation. If you changed the environment variables on the machine, only new processes spawned after that moment will have the new environment variables.
If you haven't restarted the Jenkins Slave process on that machine since changing the variables, then it won't be picked up.
Well, starting Jenkins slave process didn't help. Sending slave in offline mode and then back to online didn't help, neither.
First as we started the master Jenkins process anew, the changes in envvars on the slave took effect and the master showed the proper envvar values. But starting the Jenkins app is not a proper solution...
Related
I am having a weird issue with Environment Variables on a VM or may be there's something that I don't know about them.
I am setting few environment variables through the Azure DevOps release pipeline using the following command.
setx NameOfEnvVar ValueOfEnvVar /m
Post completion of the release pipeline the environment variable is visible through the System Properties -> Environment Variable Window.
However, when I am running the 'set' command from the command line(as Administrator) on the VM the 'NameOfEnvVar' is not showing up.
I have a python command line program that can retrieve passwords for me.
I can run it from the command line and get the passwords.
Example command:
passwordmanpro_cli javaprops OpenWeatherMap_DEV
The response comes back fine.
I have the Jenkins agent installed on the machine. I have a "Execute Windows Batch Command" step which calls exactly the same commandline.
This USED to work without an issue. A month ago it stopped working. With an error:
ERROR Success not returned from passwordmanagerpro
Using URL - https://icsecpws.cc.ic.ac.uk:443/restapi/json/v1/resources (AUTHTOKEN ommitted - 36)
ResponseCode - 200
resJSON - {'operation': {'name': 'Authentication', 'result': {'status': 'Failed', 'message': 'User is not allowed to access from this host'}}}
IP Being used to send message might be: 155.198.31.184
Something is different from how this request is sent via a windows terminal and how it is sent from a windows batch step in Jenkins.
I have verified the windows batch command is being run as a correct user.
I have verified the username and password credentials being passed are the same
I have verified the source IP by adding debug lines in python.
The password manager we are using has an API user setup and you enter an IP address the API is allowed to be called from. Apparently the restriction is not done on source IP but a reverse hostname lookup.
Can anyone give me advice on how to debug this further?
Update 1
More debugging has revealed that the cause is the environment is being set wrong. The host machine is windows 10. I have an environment variable called PASSMANCLI_AUTHTOKEN and another called PASSMANCLI_URL
In control panel I am setting both variables system wide. NOT for a particular user.
What is really strange is that the PASSMANCLI_URL is changing and being picked up ok, but the PASSMANCLI_AUTHTOKEN variable is not. I have added a "set" windows batch command in the config and I have confirmed that the PASSMANCLI_AUTHTOKEN value is NOT coming from the system setting but somewhere else. I am wondering if Jenkins does anything special with this.
BTW: I have also used the whoami command as part of the project config and confirmed Jenkins is running as the same user.
Update 2
I have gone through the entire windows registery and looked at all Environment entries and deleted PASSMANCLI_AUTHTOKEN. I have confirmed it is not in the environment console. I have restarted the Jenkins agent and the entire server. I then run my jenkins job with a single command "Set" and it reads back the OLD value of the token!
update 3
I have created a brand new Jenkins job with 1 step which is the windows batch command. It simply has "set" so displays the environment variables. I can see PASSMANCLI_AUTHTOKEN is still being set even though I have completely wiped it from the machine.
update 4
I thought it might be something to do with the way the Jenkins runner uses JAVA. (Our Jenkins runner is using Java 8 32 bit). I wrote a Java program which runs
processBuilder.command("cmd.exe", "/c", "set");
and outputs the result.
I checked the output and the variable is NOT set, as expected.
I still don't know where this variable is coming from when executed via Jenkins.
I'm trying to reset-and-launch a Windows VM (in vsphere) during a Jenkins job. I successfully installed the vSphere Cloud Plugin. I've followed instructions to setup the Windows machine as a jenkins-mvn-slave, and have it setup to run as a service.
If I click on the button in Jenkins for Launch Slave Agent, I can see (in vsphere) that the VM does a revert snapshot, and then it does a power on virtual machine. If I attach to the machine, I can see that the Jenkins service starts automatically. However, back in Jenkins, it tells me that the Slave did not come online in allowed time.
Some key settings for my slave:
Force VM launch: Checked
Wait for VMTools: Not checked
Delay between launch and boot complete: 120
Secondary launch method: Launch slave agents view Java Web Start
Versions:
Jenkins: 1.596.2
vSphere: 5.5.0
Windows: Server 2012 R2 Standard, Build 9600
vSphere plugin: 2.7
What am I missing?
I've done a lot of messing around since I posted, but I think the following is what I was doing wrong. I first got the VM working as a normal slave agent. Once I had that working, then I tried to setup the same as a vsphere-cloud-slave-agent. I wasn't realizing that setting up a host as a slave agent is "agent-name specific".
So, I uninstalled the Jenkins service, launched the "vsphere cloud slave agent", logged into the machine, and ran javaws (as specified in the previously mentioned instructions.
A couple of other gotchas that I encountered (not relevant to the initial post, but maybe relevant to someone who reads this):
I originally installed git with a password manager. Unfortunately, since jenkins jobs aren't interactive, it was hanging on the git clone command. I tried uninstalling and re-installing git, but it didn't fix the problem for whatever user the jenkins slave was running as. I ended up having to revert to a previous slave image and install git from there. (I probably could have also figured out what user was running the jenkins slave, and entered the desired password there.)
I wanted to run a clean VM for each job. I never figured out this one. If I set Availability to Take this slave on-line when in demand and off-line when idle, that was a good start. However, if I set the times to 0 and 0, then the machine was constantly rebooting. If I set the times to 1 and 1, then the machine does mostly what I want, unless there are back-to-back jobs queued to run.
I have 2 computers. Com-A, Com-B.
I have build automation functional script using selenium webdriver,Testng and maven on Com-A.
Com-A has installed everything with Jenkins but Com-B has only jenkins , Can I run build which is deployed in Com-A from Com-B? Or I will have to install all necessary software to Com-B also?
Your current setup is good enough to kick off the build remotely from Com-B to Com-A.
Please make sure the jenkins server deployed on Com-B has properly configured as Master and other nodes (ex : Com-A) as slaves.
To ensure the configurations, please follow the steps given below :
Step 1: Go to Manage Jenkins page and select Manage Nodes link
Step 2: On Manage Node page, you can see a list of nodes if already configured. Else there will be only one node named as Master by default which represents the host.
Step 3: To add new Node, give a name (ex: selenium-slave1) and select Dump Slave option to add a node as customized slave.
Step 4(a): After adding the node, configure the node as shown below.
Step 4(b): Make sure while setting the Launch Method field, Launch slave agents on Unix machines via ssh has been selected (this will communicate via ssh between master and slave nodes).
Step 4(c): configure advanced fields which are highlighted as per your settings and click save.
Step 5: Finally a new node has been added as slave and configured successfully.
Step 6(a): Now Configure a new Job to schedule it whenever it need to be run.
Step 6(b): Add a new maven job since your project has been configured using maven.
Note : Will add the job config soon.
You can make Com-A a slave machine in jenkins. Com-B will become master and mark the build to always run from Com-A node.
Refer https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines
First of all, u don't need to install all thing in COM B.
Connect with COM A with ssh(secure shell) command and than execute ur project using shell or bash script. In jenkins, u will found all build step under Build option.
i use the below command to run my project using shell script:
ssh -l user comAIpaddress(ex. 192.192.192.192) sh SciptLocationInComA.shell
this command first connect with another machine and than execute the shell script to run the project.
Run a java project using shell or bash script is quite easy..... :)
I am trying to get Jenkins to start a virtual machine on a Jenkins slave. The VM itself will then act as a Jenkins slave.
In order to do so I need to boot the VM and keep it running, even after the Jenkins job terminates. I have tried to create a freestyle project which runs a batch script on the slave and checks if the VM is running:
"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws start "D:\VM\MyVM.vmx"
"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" list
The second command shows me that the VM is actually up and running, but apparently it directly shuts down again since I can't see the node that corresponds to the VM as online.
The Jenkins Slave agent is installed as a Windows service on the VM's host and logs in as a domain user.
If I switch the first command to
"C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -x "D:\VM\MyVM.vmx"
the VM powers on, the node gets connected to Jenkins. This is because somehow the batch script gets stuck after this command and does not terminate, so the VM remains powered on. However, if I log on the host with the same user the Jenkins service uses, I cannot see the VM running.
Ironically, I can in fact power OFF any virtual machine that I have started locally on the host from Jenkins by creating a project with the batch command
"C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws stop "D:\VM\MyVM.vmx" soft
So, to summarize:
I want to create a Jenkins job that powers on a VM so I can use it as a slave agent. The VM has to remain powered on even after the job is done, I will shut it down with a different job as needed.
But only the shutdown job is working as intended.
try to start your VM with START command:
START "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" -T ws start "D:\VM\MyVM.vmx"
After playing around with VMs and Jenkins today I learned that vmrun works perfectly if the Jenkins slave does not run as a Windows service but is launched via the Java Webstart application.
Besides, one can prevent processes from getting killed by altering the BUILD_ID env. variable since Jenkins is using this variable to track the processes the build launched. So by changing the value of BUILD_ID before spawning processes they won't get killed after the Job finishes.