By default Jenkins is configured to start on HTTP port 8080 after install
Instructions to change this to use a HTTPS/SSL port with a custom certificate explained below.
These steps were followed on a windows machine.
The assumption at this point is Jenkins is up and running, and you already have an SSL certificate available in the default windows certificate store (or already have a pfx handy).
Tips:
To find JENKINS_HOME, go to dashboard and follow path
In Menu, Jenkins, Manage Jenkins, system Information (or visit in browser http://yourserver:8080/systemInfo)
Scroll down and make a note of JENKINS_HOME
To restart Jenkins, you can issue a command like
http://yourserver:8080/restart
or issue below from command line (assuming default install path in windows - JENKINS_HOME - is C:\Program Files (x86)\Jenkins)
"C:\Program Files (x86)\Jenkins\jenkins.exe" restart
Watch for any errors at
C:\Program Files (x86)\Jenkins\jenkins.err.log
Steps to run on SSL/HTTPS with custom certificate
Step A: Fix the URL Jenkins is running
Step B: Export your pfx certificate from windows (skip if you already have a pfx available)
Step C: Convert PFX to java keystore
Instructions to change this to use a HTTPS/SSL port with a custom certificate explained below.
These steps were followed on a windows machine.
The assumption at this point is Jenkins is up and running, and you already have an SSL certificate available in the default windows certificate store (or already have a pfx handy).
Tips:
To find JENKINS_HOME, go to dashboard and follow path
In Menu, Jenkins, Manage Jenkins, system Information (or visit in browser http://yourserver:8080/systemInfo)
Scroll down and make a note of JENKINS_HOME
To restart Jenkins, you can issue a command like
http://yourserver:8080/restart
or issue below from command line (assuming default install path in windows - JENKINS_HOME - is C:\Program Files (x86)\Jenkins)
"C:\Program Files (x86)\Jenkins\jenkins.exe" restart
Watch for any errors at
C:\Program Files (x86)\Jenkins\jenkins.err.log
Steps to run on SSL/HTTPS with custom certificate
Step A: Fix the URL Jenkins is running
- Navigate to Jenkins, Manage Jenkins, Configure system (or go to http://yourserver:8080/configure)
- Scroll and find "Jenkins URL" and fix this. ie; change from localhost correct server name
Step B: Export your pfx certificate from windows (skip if you already have a pfx available)
- In windows having the certificate you need to use, Start, Run, mmc, hit Enter
- File, Add Remove Snap-in, certificates, Add, Computer Account
- Locate the certificate you want to use and right click on it
- All Tasks, Export, next, select option "yes, export the private key", next, select option .PFX, "Include all certificates in the certification path if possible", "Export all extended properties"
- Next, Password, set something you remember, next and save the file.
- Lets assume the exported pfx is called myCustomCert.pfx & password is MyPass#436
Step C: Convert PFX to java keystore
- Start, Run, cmd
- In command line, naviage to the folder you have saved the pfx file
- Use java keytool to convert the certificate. Note: if you are running Jenkins with 32 bit java, you have to use 32 bit keytool to generate the certificate. To be on safer side, we will use the jre that comes with Jenkins assuming this is the one that's used to run Jenkins. Additionally, you can see I am using the same password again for import and exporting to new keystore. This was because I was running into trouble with jenkins not loading the file if I use a different password
- "C:\Program Files (x86)\Jenkins\jre\bin\keytool" -importkeystore -srckeystore myCustomCert.pfx -srcstoretype pkcs12 -srcstorepass MyPass#436 -destkeystore myCustomCert.jks -deststoretype jks -deststorepass MyPass#436
- Copy the generated myCustomCert.jks to JENKINS_HOME (in the default case C:\Program Files (x86)\Jenkins)
- Edit jenkns.xml from JENKINS_HOME (C:\Program Files (x86)\Jenkins). I have used Visual Studio Code as notepad is not able to read the file properly (formatting mess)
- Find line like below
-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war" - Change as below (changes bolded)
-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=-1 --httpsPort=8080 --webroot="%BASE%\war" --httpsKeyStore="%BASE%\myCustomCert.jks" --httpsKeyStorePassword=MyPass#436 - Restart Jenkins
- After restart you should be able to access Jenkins via the https protocol; (eg. https://yourserver:8080)
4 comments:
hi , how to change jenkins port to 443 instead of 8080. Cause i need to configure webhook in JIRA to call jenkins job. JIRA only accepts 80 and 443.
Change in the jenkins.xml . HttpsPort=443/80
Hi, process of creating java key store is same for all windows server versions and certificates? and -'srcstoretype pkcs12' is constant or varies based on certificates?
Is above process is possible with domain level ssl?
Post a Comment