Skip to content

Instantly share code, notes, and snippets.

@mnojek
Last active April 22, 2021 17:55
Show Gist options
  • Save mnojek/b459f1a46ff429e0a548efa7120be58e to your computer and use it in GitHub Desktop.
Save mnojek/b459f1a46ff429e0a548efa7120be58e to your computer and use it in GitHub Desktop.
How to move Jenkins from one drive to another on Windows

How to move Jenkns to another drive on Windows?

  1. Move entire Jenkins directory (typically located in C:\Program Files (x86)\Jenkins) to desired one (e.g. D:\Jenkins) - it can take some time
  2. Turn off Jenkins
    • Open cmd where it is installed (C:\Program Files (x86)\Jenkins) and run jenkins.exe stop
    • Open Services in Windows (Win key and type "Services") and find Jenkins service, right-click and click Stop
  3. Update environment variables
    • Search in Windows for 'environment variables'
    • Look for JENKINS_HOME in system variables and edit it
    • Change the value (in our case D:\Jenkins)
  4. Change service "Path to executable"
    • Open cmd with Admin privileges (type cmd in start and then click 'Run as administrator')
    • Check Jenkins service info by running sc qc Jenkins
    • Example of response:
    [SC] QueryServiceConfig SUCCESS
    
    SERVICE_NAME: Jenkins
        TYPE               : 10  WIN32_OWN_PROCESS
        START_TYPE         : 2   AUTO_START
        ERROR_CONTROL      : 1   NORMAL
        BINARY_PATH_NAME   : "C:\Program Files (x86)\Jenkins\jenkins.exe"
        LOAD_ORDER_GROUP   :
        TAG                : 0
        DISPLAY_NAME       : Jenkins
        DEPENDENCIES       :
        SERVICE_START_NAME : .\Automation
    
    • Notice that BINARY_PATH_NAME leads to old place of installation
    • Run sc config <service_name> binPath= <path_to_binary>, e.g. sc config Jenkins binPath= "\"D:\Jenkins\jenkins.exe\""
    • You will be notified with response [SC] ChangeServiceConfig SUCCESS
    • In case that you receive [SC] OpenService FAILED 5: Access is denied., you probably forgot to open cmd with admin privileges
    • Notice the space after binPath= and also make sure to escape all quote (") characters
    • Run sc qc Jenkins again to confirm the changes are made
  5. Run Jenkins by executing jenkins.exe start in cmd opened in new installation folder
    • Check if the service is up and running (you probably need to Refresh the services list using button at the top bar or simply by clicking F5)
  6. Open your configured Jenkins URL, go to Manage Jenkins -> Configure System and check if Home directory is set properly
  7. Congratulations, you can now run your jobs and use Jenkins as usual!

Sources: Modifying the “Path to executable” of a windows service Change Jenkins Home location Move Jenkins Installation Directory and Assign it a Dedicated Windows User Account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment