0
0
Jenkinsdevops~7 mins

Managing Jenkins URL and security - Commands & Configuration

Choose your learning style9 modes available
Introduction
Jenkins is a tool that helps automate tasks like building and testing software. Managing its URL and security settings ensures only the right people can access it safely and that the web address is correct for users.
When you want to change the web address Jenkins uses to be easier to remember or fit your company domain
When you need to secure Jenkins so only authorized users can access it
When you want to enable HTTPS to encrypt data between users and Jenkins
When you want to disable anonymous access to protect your build jobs
When you want to configure security settings after installing Jenkins for the first time
Commands
Open the Jenkins default configuration file to change the Jenkins URL and port settings.
Terminal
sudo vi /etc/default/jenkins
Expected OutputExpected
No output (command runs silently)
Restart Jenkins to apply the changes made to the configuration file.
Terminal
sudo systemctl restart jenkins
Expected OutputExpected
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2024-06-14 10:00:00 UTC; 5s ago Main PID: 1234 (java) Tasks: 30 (limit: 4915) Memory: 200.0M CGroup: /system.slice/jenkins.service └─1234 /usr/bin/java -jar /usr/share/jenkins/jenkins.war
Allow traffic on port 8080, which is the default Jenkins port, so users can access Jenkins through the firewall.
Terminal
sudo ufw allow 8080
Expected OutputExpected
Rule added Rule added (v6)
Edit Jenkins main configuration file to enable security settings like disabling anonymous access and enabling user authentication.
Terminal
sudo vi /var/lib/jenkins/config.xml
Expected OutputExpected
No output (command runs silently)
Restart Jenkins again to apply the security configuration changes.
Terminal
sudo systemctl restart jenkins
Expected OutputExpected
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2024-06-14 10:05:00 UTC; 5s ago Main PID: 1234 (java) Tasks: 30 (limit: 4915) Memory: 200.0M CGroup: /system.slice/jenkins.service └─1234 /usr/bin/java -jar /usr/share/jenkins/jenkins.war
Key Concept

If you remember nothing else, remember: changing Jenkins URL and security settings requires editing config files and restarting Jenkins to apply changes safely.

Common Mistakes
Changing Jenkins URL without restarting the Jenkins service
Jenkins will continue running with old settings until restarted, so changes won't take effect.
Always restart Jenkins after changing URL or port settings.
Not allowing Jenkins port through the firewall
Users cannot access Jenkins even if it is running because the firewall blocks the traffic.
Open the Jenkins port (default 8080) in the firewall to allow user access.
Disabling security without setting up user authentication
This leaves Jenkins open to anyone, risking unauthorized access and changes.
Enable security and configure user authentication before disabling anonymous access.
Summary
Edit /etc/default/jenkins to change Jenkins URL and port.
Restart Jenkins service to apply URL and port changes.
Open Jenkins port in firewall to allow access.
Edit /var/lib/jenkins/config.xml to enable security settings.
Restart Jenkins again to apply security changes.