How to prevent auto-closing of Tomcat on starting from Jenkins job? - batch-file

I am trying to start Tomcat in my Jenkins job on a slave machine.
I start Jenkins slave manually by opening slave-agent.jnlp
This is what I tried in Execute Windows Batch Command:
call C:\tomcat\bin\startup.bat
Tomcat starts on running the build and the build is marked successful but then Tomcat auto closes after few seconds.

This is Jenkins Process Tree Killer in action. This is by design. You can either disable it globally for the whole Jenkins (not recommended) by starting Jenkins with extra parameter
-Dhudson.util.ProcessTree.disable=true.
For Windows environment, you can use the at command to schedule start of Tomcat (with 1 sec delay).

Related

why running a batch file from jenkins spends more time than running the batch file directly

I am using jenkins to do CI, and in one of my jenkins job's jenkins file
I try to run a batch file which is in a slave agent of jenkins (windows 7 OS), and the batch file is as below:
#echo on
"<path1>\eclipse.exe -noSplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild -data E:\jenkins\build_workspace -cleanBuild <project name>/Debug
exit
and in my jenkinsfile, it is like:
pipeline {
agent {label "buildserver"}
stage {
script {
bat 'call <path2>\abc.bat'
}
}
}
and total build time is about 16-18 minutes.
but when I login in the build server, and try to run the batch file directly in the command line window, the build process time is about 4-5 minutes.
I do not know what is going on ?
This issue has been solved. It is the reason of jenkins agent installed as windows service on slave agent of win 7 OS, probably the compatibility between win 7 and jenkins.
refer to Jenkins job windows batch execution 20 times slower than executing in cmd.exe.

SQL Server Agent Job and gsutil

I can successfully run a gsutil command with a windows domain account from the command line in Windows (setting up service account key etc.). When I try to run the same command from a SQL Agent Job using a CmdExec task the job hangs and doesn't complete. I can't see any logging so have no clue what it's waiting for. I've setup the job to run with the same Proxy User that i use to run the gsutil command manually.
Any ideas how I can get this to work or how to see more logging?
Are you using standalone gsutil? Or did you get it as part of installing the Cloud SDK (gcloud)?
If the job hangs for a long time, it could be stuck retrying multiple times. To test if this is the case, you can set the num_retries option to be very small, but above 0 (e.g. 1) either in your .boto file or the the command arguments via this option:
gsutil -o 'Boto:num_retries=1' <rest of command here...>
A second thing to note (at least for the version of gsutil that doesn't come with gcloud) is that gsutil looks for your boto config file (which specifies the credentials it should use) in your home directory by default. If you're running gsutil as a different user (maybe your SQL Agent Job runs as its own dedicated user?), it will look for a .boto file in that user's home directory. The same should apply for the gcloud version -- gcloud uses credentials based on the user executing it. You can avoid this by copying your .boto file to somewhere that the job has permission to read from, along with setting the BOTO_CONFIG environment variable to that path before running gsutil. From the cmd shell, this would look something like:
set BOTO_CONFIG=C:\some\path\.boto && gsutil <rest of command here...>
Note: If you're not sure which boto config file you're normally using, you can find out by running gsutil version -l and looking at the line that displays your config path(s).

How to run a batch file from Jenkins

I am trying to run a batch file from Jenkins but I can't get it to run.
In the pre-build step I have entered the file I want to execute but I get the stacktrace shown below. Jenkins doesn't recognize the cmd command.
How can I fix this?
Your Linux Jenkins slave doesn't support cmd. In order to workaround it you have several options (from better to worse):
Add a Windows slave to Jenkins and run cmd from there.
Port your batch file to bash or similar and run it from your Linux Jenkins slave.
Add some kind of DOS emulator (Wine, DOSBox, DOSemu) in your Linux Jenkins slave.
My advice: If you know Linux & Bash or you have no control of Jenkins go for option 2. Otherwise go for option 1. Avoid option 3.
You're trying to run CMD on a LINUX machine. either change the slave you're running to Windows machine or migrate the Batch script to shell script.
Good luck!

On Linux CentOS 7 OS how schedule jobs to run drush to re-index solr, run cron and clear cache for drupal 7 sites

HI a newbie to server management... We need to automate hourly script to run drush to re-index solr, run cron and clear cache on multiple servers. I'm sure there has to be .bat file or something?
At first: You have no '.bat' files in any unix system (but ofcourse you can write scripts named something.bat, but nothing special happens ;-)).
You need to have drush installed somewhere in your sytem. I use to install it in /usr/local/share/drush and put a link from /usr/local/share/drush/drushto /usr/local/bin/drush. Then run crontab -e to edit the schedule. An editor is launched inside your console window. If it shows an empty window or the file contains only lines starting with "#", then put
MAILTO=your.mail#example.com
PATH=/usr/local/bin:/bin:/usr/bin:$HOME/bin
#daily drush #live -q -y cron > /dev/null
In this case drush cron is executed daily for a drupal installation with a site-alias #live. The output is sent to /dev/null, so that I do not get any error messages.
PS: Get familiar with the cron systems and the crontab command as well as shell scripting. They are unix' standard tools and are needed for those kind of tasks.
PS2: You also want to know the concept of drush site-aliases. Run drush topic docs-aliases to learn more about it.

Why does this jenkins job never complete?

I have a windows 8 jenkins slave (really more than one) and I want to have a task which clones a mirror of a git repository if it doesn't exist and always fetches latest.
I've got this 'execute windows batch' step:
if not exist "server-reference" (
git clone --mirror git#ssh.com:something/somewhere.git server-reference
)
pushd server-reference
git fetch --all
popd
exit /B %ERRORLEVEL%
The console output for the job gets to this point
c:\jenkins\workspace\thing\server-reference>git fetch --all
Fetching origin
and never finishes
If I switch an exit above the fetch then I get the expected exit.
And if I run the batch file commands as the jenkins user on the windows box everything works as expected. So I (think I) know that the git fetch --all runs on the slave without prompting for input
How do I amend this script so that it completes when Jenkins runs it?
A number of things can cause this problem. Here are things that have worked for me in the past.
I know you stated this above, but just to double-check: Confirm that when you run git fetch --all manually on the slave machine, it doesn't prompt you for a password. If it does, Jenkins would get stuck on that step, so you'll need to set up an SSH keypair.
Make sure that you are calling C:\Program Files (x86)\Git\cmd\git.exe and not C:\Program Files (x86)\Git\bin\git.exe in Jenkins. The second one can cause this problem in certain versions of git.
On the slave machine, set the environment variable HOME to C:\users\[username], filling in your user's username. (For older OS's it was C:\Documents and Settings\[username].) Then recycle the Jenkins service and try again.
Double check that in Administrative Tools > Services, the Jenkins slave service "Log On As" is set to your user and the password is correct. If not, set those values, recycle the Jenkins service and try again.
If none of the above worked, try uninstalling and reinstalling git. And if you aren't using it, try installing the newest version of git.

Resources