How to set up more than one Jenkins on window

Many times we need to install more than one instance of Jenkins on the same window machine. Along with installation, we need also setup window service so that Jenkins can itself start after the system reboot.

Let suppose you have already one instance of Jenkins is running, now you need to install another for this you need a Jenkins.war to install Jenkins as well java installed on the system.

Start Service:

Run below command. –DJENKINS_HOME is the path of Jenkin_Home where installation file will be install

java -DJENKINS_HOME=/path/to/configs -jar jenkins --httpPort=<port_num>
// java -DJENKINS_HOME=D:/Jenkins -jar jenkins.war --httpPort=8081

Now start you Jenkins with URL http://<hostname>:<your_port>. Let assume http://localhost:8081. It will start as a normal installation. Follow all processes of normal installation. After the installation process completed follow the below steps with the assumption that your port is 8081 and Jenkins_Home is “D:/Jenkins

sc.exe create <service_name> binpath= "<path_to_jenkins.exe>" displayname= <service_displayname> start=auto

//Example
// sc.exe create jenkins_new binpath= "D:/jenkinsjenkins.exe" displayname= "jenkins_new" start=auto

A space is required between value and equal sign. ex. binpath= "value"

<service_name>:
Specifies the name given to the Service key in the registry. Note that this is different from the display name (which is what you see with net start command and the Services tool in Control Panel.)

<service_displayname>:
is the label that will identify the service in the service manager interface.

<path_to_jenkins.exe>:
path of jenkins.exe. It is normally exists at JENKINS_HOME path

Run above command cmd (open as administrator). If everything successful 👌 you will see the below message.

Service installation
Create Service

If service is stopped then you can start from service manager.

Delete service:

You can also delete created service with the below command

sc delete <service_name>
//Example
// sc delete jenkins_new
Jenkins service delete
Service deleted

Start/Stop/Restart Jenkins:

Open Console/Command line –> Go to your Jenkins installation directory. Execute the following commands respectively:

  • To stop:
    • jenkins.exe stop
  • To start:
    • jenkins.exe start
  • To restart:
    • jenkins.exe restart

To stop Jenkins Please avoid shutting down the Java process or the Windows service. These are not usual commands. Use those only if your Jenkins is causing problems.

Use Jenkins’ way to stop that protects from data loss.

http://[hostname]/[command]

where [command] can be any one of the following:

  • exit
  • restart
  • reload

Example: If my local PC is running Jenkins at port 8080, it will be

http://localhost:8080/restart

Reference: https://stackoverflow.com/questions/14869311/start-stop-and-restart-jenkins-service-on-windows

Leave a Reply