Jenkins is not picking up Environment variable to be used in windows batch script - visual-studio-2010

I am building a visual studio solution containing number of project. I wanted to disable multiprocess build, so , i tried setting an enviroment variable CL to /MP1. But it didn't worked in Jenkins while working in running the batch script for building solution using command line.

Good morning,
Log to your Jenkins server, and stop the Jenkins from the command line. While doing this, open your web-browser and refresh the Jenkins webpage to make sure it stopped(it will take around 5 seconds to stop the service). Then start again from the command line, it will update the variable. I did yesterday, to run my unit tests. It should work.

To set environment variables for individual projects, use the checkbox 'Prepare an environment for the run' and set what environment variables you want in the format 'ENV=value' in the Properties content box.
Otherwise, all I can suggest is that you haven;t restarted the Jenkins service after setting your variable in Windows.

You can also used the EnvInject plugin, it works well.
https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

Related

How to run pre/post job scripts on self-hosted GitHub Actions runner

Problem
I am trying to use a Windows Docker container to run GitHub Actions.
I want to run scripts before and after the job (e.g. to clean the directory).
I have successfully done this before on a computer not running docker, so I figured the same should work in docker.
What I have tried
I found here that you can do that using Environment Variables.
I used the following two commands in command prompt to set the environment variables.
Pre-Job Script:
setx ACTIONS_RUNNER_HOOK_JOB_STARTED C:\actions-runner-resources\scripts\pre-post-build\pre-run-script.ps1
Post-Job Script:
setx ACTIONS_RUNNER_HOOK_JOB_COMPLETED C:\actions-runner-resources\scripts\pre-post-build\post-run-script.ps1
The scripts do not run.
I have tried restarting the docker container.
I have tried restarting the actions runner service.
I am new to docker, so I am wondering if I am doing something wrong with the environment variables that does not work with docker.
How do I get the actions runner to run pre/post job scripts in docker?
You can safely add them to your environment variable by doing this recommended method;
Inside the actions-runner directory, locate the .env file, edit it by adding your environment variable. Save and restart the runner service.

The JMETER_HOME environment variable is not defined correctly

I'm getting this error when trying to run this jmeter sentence from a maven project in java.
jmeter -g DIRECTORY -o DIRECTORY
When I run it in cmd it works perfectly but when I try to run it using this:
processBuilder.command("cmd.exe","/c","jmeter -g DIRECTORY -o DIRECTORY");
processBuilder.directory(new File("C:\\apache-jmeter-5.3\\bin"));
try {
Process process = processBuilder.start();
It says The JMETER_HOME environment variable is not defined correctly
When I run the command echo %JMETER_HOME% it returns C:\apache-jmeter-5.3
What I found weird is that in other PC it all works fine and that one doesn't have the JMETER_HOME variable defined, so I tried deleting the variable from this PC but it won't delete, it's not appearing in the system variables window but when I echo it's there.
What is going on?
Thanks in advance
So you want us to guess what is the difference between one your PC and the other one without providing any information apart from incomplete code?
I can only state that I cannot reproduce your issue and yes, I don't have JMETER_HOME variable set anywhere.
If you're using Maven maybe it worth considering looking at JMeter Maven Plugin which can automatically download JMeter, run the test and generate the HTML reporting dashboard.
Also be informed that according to JMeter Best Practices you're supposed to use the latest version of JMeter so consider upgrading to JMeter 5.4.3 (or whatever is the latest version of JMeter available at JMeter Downloads page) on next available opportunity.
I faced same issue of JMETER_HOME not been set, even though I tried setting that Env variable.
I was tying to launch the Jmeter on the Virtual system (VM) using command prompt, and didn't succeed.
I able to solve it by running the command prompt as admin and launching Jemter, it worked fine.
Note: make sure you have the set the Env. PATH set to the bin folder of Jmeter

Running .bat commands on a Jenkins slave with restricted execution permissions

I am running a Jenkins slave on a restricted environment. This environment will only allow me to execute files in a specific directory.
The problem I have is running simple batch commands.
The slave's java.io.tmpdir being AppData/Local/Temp, jenkins will copy my command in a temp bat file and attempt to run it, like such:
cmd /c call D:\Users\TastyWithPasta\AppData\Local\Temp\hudson8090039221524722157.bat
Here the issue becomes obvious, the command cannot be run due to restriction and the build fails.
Anybody working in a restricted environment and facing the same issues? What would be a good workaround?
Unfortunately, -Djava.io.tmpdir=newpath is not an option since this taps into the Java installation. Maybe there is a way to override it locally?

command not found in jenkins running on Mac machine

I predominantly work on windows OS and quite new to MAC systems. I am trying to set up Jenkins CI tool on one of the MAC machines, I have installed jenkins on mac and it is running on 8080 port.
Issue: I am getting the following error on Jenkins console output when i execute the job:
**/var/folders/zz/zzzivhrRnAmviuee+++++E++++2/-Tmp-/hudson6910375920437308281.sh: line 13:
**ampts: command not found**
Build step 'Execute shell' marked build as failure**
Things I tried:
I added the correct path in .bash_profile and since then I am able to successfully run the ampts command from terminal and every thing works fine from terminal. But the same does not run from the execute shell in Jenkins which is running on MAC.
Earlier the job was running as anonymous I created the account in jenkins and placed .bash_profile with the correct path under ~jenkins/users/home/my.account and restarted jenkins but still I am facing the same issue.
I also tried placing .bashrc under ~jenkins and also under ~jenkins/users/home/my.account but still no success.
Can some one point out what I am missing. or what needs to be done in case of Jenkins running on MAC.
This will depend on how you've started the Jenkins client. If you start it from the command line with the javaws command then I think this will inherit the environment variables of the terminal prompt. If you start the JNLP agent from the browser then it will inherit the system environment (which is different to the bash environment). There's a few things you could try:
Set the PATH variable explicitly in the ~/.MacOSX/environment.plist file (see the Apple docs)
If you are using Ant to run the jobs then you can add the environment variable to the ~/.antrc file (same syntax as the .bash_profile)
Set the environment variable in the Jenkins configure page for this node.

Set global environment variables inside Xcode build phase run script

I'm using Jenkins to do continuous integration builds. I have quite a few jobs that have much of the same configuration code. I'm in the midst of pulling this all out into a common script file that I'd like to run pre and post build.
I've been unable to figure out how to set some environment variables within that script, so that both the Xcode build command, and the Jenkins build can see them.
Does anyone know if this is possible?
It is not possible to do exactly what you ask. A process cannot change the environment variables of another process. The pre and post and actual build steps run in different processes.
But you can create a script that sets the common environment variables and share that script between all your builds.
The would first call your shell to execute the commands in the script and then call xcodebuild:
# Note the dot in the beginning of the next line. It is not a typo.
. set_environment.sh
xcodebuild myawesomeapp.xcodeproj
The script could look like this:
export VARIABLE1=value1
export VARIABLE2=value2
How exactly your jobs will share the script depends on your environment and use case. You can
place the script in some well-known location on the Jenkins host or
place the script in the version controlled source tree if all your jobs share the same repository or
place the script in a repository of its own and make a Jenkins build which archives the script as a build artifact. All the other jobs would then use Copy Artifact plugin to get a copy of the script from the artifacts of script job.
From Apple's Technical Q&A QA1067 it appears that if you create the file /Users/YOU/.MacOSX/environment.plist and populate it with your desired environment variables that all processes (launched by the user with the environment.plist file in their home dir) will pick up these environment variables. You may need to restart your computer (or just log out and back in) before a newly launched process will pick up the variables.
This article also claims that Xcode will also pass these variables to a build phase script. I have not tested it yet but next time I restart my MacBook I will let you know if it worked.
From http://developer.apple.com/library/mac/#/legacy/mac/library/qa/qa1067/_index.html
Q: How do I set environment for all processes launched by a specific
user?
A: It is actually a fairly simple process to set environment variables
for processes launched by a specific user.
There is a special environment file which loginwindow searches for
each time a user logs in. The environment file is:
~/.MacOSX/environment.plist (be careful it's case sensitive). Where
'~' is the home directory of the user we are interested in. You will
have to create the .MacOSX directory yourself using terminal (by
typing mkdir .MacOSX). You will also have to create the environment
file yourself. The environment file is actually in XML/plist format
(make sure to add the .plist extension to the end of the filename or
this won't work).

Resources