Jenkins Windows silent msi installation-How do I customize Jenkins installation directory?

I have been trying to silently install Jenkins 2.361.1 LTS on Windows using the community msi installer. My PowerShell script downloads and installs Jenkins with no problem, but I’m unable to customize Jenkins installation folder. No matter what command line installer properties I set it always end up installing under C:\Program Files\Jenkins\ .Below is an example PS script (although I have played with multiple other versions of the properties) TARGETDIR and JENKINSDIR have no effect. In the log file I observe that some of the properties revert to default values.
Any advice on whether what I’m trying to do is possible?

#Windows PS silent Install for jenkins.EXE
#Using Windows Installer

#Create Setup  and  Program installation folders
$setupBase='C:\SERVER_SETUP\jenkins_v2.361.1_LTS'
$progBase='D:\DEVTOOLS\jenkins'
New-Item -Path $setupBase -ItemType Directory
New-Item -Path $progBase -ItemType Directory

#Download JENKINS from Jenkins

[Net.ServicePointManager]::SecurityProtocol = “Tls, Tls11, Tls12, Ssl3”
#Note need to provide name in OutFile path
Start-BitsTransfer -Source  https://myServer.example.net/job/FILE_UPLOAD/175/artifact/jenkins.msi -Destination "$setupBase\jenkins.msi"

<#Argument explanation
/i : product.msi
/qn : no UI
/L : log verbose
#>

$MSIArguments = @(
    "/i"
    "$setupBase\jenkins.msi" 
    "ALLUSERS=0"
    "TARGETDIR=$progBase"
    "JENKINSDIR=$progBase"
    "/qn"
    "/norestart"
    "/L*v"
    $logFile    
)

#Install jenkins silently
$timestamp = Get-Date -format yyMMdd-HHmmss
$logFile = "$setupBase\jenkins_install_" + $timestamp + ".log"

Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

# (optional) set JENKINS_HOME a System (Machine) HOME environment variable
Write-Host "Setting JENKINS_HOME to $progBase" -ForegroundColor Green
[Environment]::SetEnvironmentVariable('JENKINS_HOME',$rBase, 'Machine')

<#Unistall Jenkins script
$timestamp = Get-Date -format yyMMdd-HHmmss
$logFile = "$setupBase\jenkins_uninstall_" + $timestamp + ".log"
$MSIArguments = @(
    "/uninstall"
    "$setupBase\jenkins.msi"
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow
 #>

Example from Log File

Apparently, the (not-so) magic command line argument is : INSTALLDIR
I know, I know what could be more obvious…but nonetheless this is not a documented command line argument for the msi installer or for the public installer properties so…

The following modified MSIArguments arguments install Jenkins in a user specified location.

$MSIArguments = @(
    "/i"
    "$setupBase\jenkins.msi" 
    "INSTALLDIR=$progBase"
    "/qn"
    "/norestart"
    "/L*v"
    $logFile    
)

I don’t think we currently have docs for the properties for the installer, there should definitely be some. I’ll see what I can do.

1 Like

Thanks @slide_o_mix .That would be very useful! There is hardly any documentation on ‘silent installations’ of Jenkins out there in the first place, and believe me I looked hard :wink:

Just for your info, these are the available properties you can override on the commandline

INSTALLDIR - The installation directory
PORT - The port Jenkins will listen on
JAVA_HOME - The directory with the Java runtime (11 or 17)
SERVICE_USERNAME - The username the service will run as
SERVICE_PASSWORD - The password for the service user.

I’ll try and add something to the install docs with this info.

1 Like

I created this pull request to add the silent install information. Add information about silent install on Windows by slide · Pull Request #5478 · jenkins-infra/jenkins.io · GitHub

1 Like

Very useful indeed. Thank you @slide_o_mix

hi, i tried to run this code but i have a problem. First of all, your jenkins.msi download link is not working. I found a solution to this problem by giving the jenkins.msi path in my locale, but now I can’t give the location of java to the jenkins.xml file. Can you help me?
@imoutsatsos @slide_o_mix

Downloading from here works fine for me: Jenkins download and deployment. I just clicked on the “Windows” link on that page and the installer downloads. Did you get an error? What mirror was used? Please provide more information on the download issue.

Can you give more details on what you have tried for installing? Like actual command you used. Without this, we would just be guessing at a possible issue.

I actually want to set up the jenkins to the virtual machines. When I tried to run the powershell script on the above it gave an “couldn’t reach the link” error. After that I download the jenkins.msi file from the internet in localime I copyied its road and paste to this. And now I had to put the java into the jenkins.xml but I can’t do it with powershell. I can set it up from the link but it is not what I want. When I checked about the silent sections from the jenkins file I coulnd’t run the code which is in there. A information screen just showed up onto my screen. Screen is like this @slide_o_mix
msiexec.exe-0BDEAEA7BB4AE7822416CD37EA8EE00D-1

It looks like you are invoking msiexec incorrectly, but you haven’t shown your command. Msiexec only shows this window if you invoke it incorrectly.

I take the order from jenkinsin’s own page. The order that I code is below @slide_o_mix

Your string is incorrect for the command, you can’t just put things on separate lines in a string in PowerShell. Look up here-strings in the PowerShell docs.

For to read it easly I wrote them one under the other. Even if they all on the same line it gaves warning

Do you really have a space between JAVA_HOME= and the path?