DEV Community

Cover image for Setup Jenkins to autostart after windows restart/reboot
cuongld2
cuongld2

Posted on • Updated on

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.

Alt Text

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:

<service>
  <id>Jenkins</id>
  <name>Jenkins</name>
  <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.
  -->
  <executable>%BASE%\jre\bin\java</executable>
  <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\
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

Alt Text

Put the bat file into that folder.

Alt Text

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

Alt Text

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

Notes: If you feel this blog help you and want to show the appreciation, feel free to drop by :

This will help me to contributing more valued contents.

Oldest comments (2)

Collapse
 
famduong profile image
PhamDuong

OMG! You save my day :D

Collapse
 
cuongld2 profile image
cuongld2

yeah.
I'm really glad that I could help someone in their way.
Thank you for reading my blog post.
:d