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.

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