DEV Community

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

Posted on • Edited 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 <arguments></arguments>

2.Create the batch file:


In my case it looks like:



````javascript

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](https://thepracticaldev.s3.amazonaws.com/i/d93ofsv4i1r2d1i57jej.PNG)


Put the bat file into that folder.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/29s4ttjjuyy9hoglol46.PNG)

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

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/jbj0bhr9zhx0mgv70ksp.PNG)

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 :

[<img src="https://thepracticaldev.s3.amazonaws.com/i/cno42wb8aik6o9ek1f89.png">](https://www.buymeacoffee.com/dOaeSPv
)

This will help me to contributing more valued contents.
Enter fullscreen mode Exit fullscreen mode

Top 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