Setup Jenkins to autostart after windows restart/reboot

Hello folks

Recently, I need to setup Jenkins as implementation for automation test on browser on different OS.

One of the problem is that when I restart the master node, the Jenkins is restarted too but almost all of the jobs and builds.

If you met this problem, I have a workaround.

Image for post
Image for post

Instead of auto run the Jenkins like configuration in jenkins.xml, I run the batch file after the windows restarted automatically.

We will need to do 2 things.

1.Disable the auto run for jenkins in jenkins.xml

jenkins.xml as in my case is located in C:\Program Files (x86)\Jenkins

jenkins.xml file looks like this:

<description>This service runs Jenkins automation server.</description>
<env name="JENKINS_HOME" value="%BASE%"/>
if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

You need to clear the argument value like this

2.Create the batch file:

In my case it looks like:

cd C:\Program Files (x86)\Jenkins
java -Dhudson.util.ProcessTree.disable="true" -Dhudson.model.DirectoryBrowserSupport.CSP="sandbox allow-scripts; default-src 'none'; img-src 'self' data: ; style-src 'self' 'unsafe-inline' data: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ;" -jar jenkins.war

Open notepad application -> save the file.bat like above

Then put the bat file into startup folder

Click on windows icon -> go to Run -> type shell:startup -> run

Image for post
Image for post

Put the bat file into that folder.

Image for post
Image for post

And next time you restarted the windows, jenkins will restart too.

Image for post
Image for post

I hope this will help you.
Just a quick note to the future.

Originally published at on September 25, 2019.

Written by

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store