55

I was wondering how one could change Jenkins' default port 8080. Using linux or windows, this is simply done with the configuration file. But the Mac config file of Jenkins looks completely different from the other ones.

Of course one could pass the --httpPort parameter when starting the server, but I want to do this within a config file.

Is there an option for that?

PS: Passing the Jenkins instance through apache would kinda solve the problem, but I want to change the Jenkins port.

Thanks!

ifeegoo
  • 7,054
  • 3
  • 33
  • 38
Tom Ferguson
  • 853
  • 2
  • 8
  • 7
  • 2
    Althogugh this comes a bit late: You should read the documentation of the Jenkins installer. You can find it in /Library/Documentation/Jenkins (unless you customized the installation and chose not to install the documentation.) – sti Mar 22 '12 at 22:19

7 Answers7

160

it looks like the default way is:

#add the default parameters - this will edit /Library/Preferences/org.jenkins-ci.plist

sudo defaults write /Library/Preferences/org.jenkins-ci httpPort 7070

#stop

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

#start

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
alex
  • 1,601
  • 2
  • 10
  • 2
  • This works! The first command needs the sudo as well, though. I got a "Could not write domain org.jenkins-ci; exiting" otherwise. – Christoph Dietze Jul 13 '12 at 00:01
  • 7
    This should be marked as correct question. The other one is too messy. – jayarjo Jul 23 '12 at 08:41
  • Cool but what about several installations? There is another answer dealing with that. Still Jenkins just needs to do this in a cleaner way. – Jonny Dec 02 '13 at 06:10
  • Exceptional answer. Just to note if you receive `/Library/LaunchAgents/org.jenkins-ci.plist: Could not find specified service` you could try execute stop/start command without `sudo`. – hris.to Dec 14 '15 at 09:32
  • thanks for this. I know jenkins but I'm new to jenkins on mac. I agree this should be the accepted answer. – Kirsteen Oct 05 '17 at 14:25
36

Before modify the Jenkins port on macOS,you must pay attention to the way of installation of Jenkins.

Here I recommend you install Jenkins by 'Homebrew' if you want to deal with iOS project building,because you may meet some errors that the way of using .pkg to install,it's really hard to solve the problems.

I have installed Jenkins LTS by brew command:

brew install jenkins-lts

So my Jenkins plist file is here:

/usr/local/Cellar/jenkins-lts/2.121.2/homebrew.mxcl.jenkins-lts.plist

You can modify the httpPort value from default 8080 to the other value,and then save the file.

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>homebrew.mxcl.jenkins-lts</string> <key>ProgramArguments</key> <array> <string>/usr/libexec/java_home</string> <string>-v</string> <string>1.8</string> <string>--exec</string> <string>java</string> <string>-Dmail.smtp.starttls.enable=true</string> <string>-jar</string> <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string> <string>--httpListenAddress=127.0.0.1</string> <string>--httpPort=8383</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>

sudo launchctl unload command will not work for you.You must try these commands to restart your Jenkins and make the port modification works.

brew services stop jenkins-lts brew services start jenkins-lts

ifeegoo:~ ifeegoo$ brew services stop jenkins-lts Stopping `jenkins-lts`... (might take a while) ==> Successfully stopped `jenkins-lts` (label: homebrew.mxcl.jenkins-lts) ifeegoo:~ ifeegoo$ brew services start jenkins-lts ==> Successfully started `jenkins-lts` (label: homebrew.mxcl.jenkins-lts)

Note:If you installed Jenkins LTS,you must pay attention that your command must be jenkins-lts,not jenkins.

ifeegoo
  • 7,054
  • 3
  • 33
  • 38
  • This also works if you navigate to /usr/local/opt/jenkins-lts or which ever version of jenkins you have installed. I used the command 'sudo nano' in order to make sure I had edit permissions for the file. – Bob Small Jul 04 '19 at 18:40
  • 1
    Given that jenkins now recommends using homebrew to install on macOS, this is definitely the way to go. Super easy. Just modify `homebrew.mxcl.jenkins.plist` (make a backup first), the run `brew services restart jenkins`. Done. – d512 Dec 18 '19 at 20:04
  • Thank you sooo much! Using that plist config file I finally got Jenkins to answer not only local but also local-network requests using a `.local` or IP address by changing to `--httpListenAddress=0.0.0.0` :) – Robert Jul 29 '20 at 12:22
  • 1
    If you are not proficient in vim/vi/nano and can't find it through Finder, you can use BBEdit's "Open file from path..." feature to edit the above file (after you deducted the actual path from the Terminal). – Luc Bloom Jun 23 '21 at 11:35
17

I'll walk you through it:

cd /Applications/Jenkins sudo vi winstone.properties Add httpPort=9999 to the file. To see all the options you can put in there type java -jar jenkins.war --help

run java -jar jenkins.war from /Applications/Jenkins. Your port will be changed. jenkins.war picks up config options from ./winstone.properties by default.

Andrew-Finnells-MacBook-Pro:Jenkins afinnell$ pwd
/Applications/Jenkins
Andrew-Finnells-MacBook-Pro:Jenkins afinnell$ ls -al
total 87928
drwxr-xr-x   4 root  wheel       136 Aug 21 12:32 .
drwxrwxr-x+ 83 root  admin      2822 Aug 21 12:05 ..
-rwxr-xr-x   1 root  wheel  45014470 Aug 19 13:14 jenkins.war
-rw-r--r--   1 root  wheel        14 Aug 21 12:32 winstone.properties
Andrew-Finnells-MacBook-Pro:Jenkins afinnell$ sudo cat winstone.properties 
httpPort=9494
Andrew-Finnells-MacBook-Pro:Jenkins afinnell$ java -jar jenkins.war
Running from: /Applications/Jenkins/jenkins.war
webroot: $user.home/.jenkins
[Winstone 2011/08/21 12:33:19] - Beginning extraction from war file
Jenkins home directory: /Users/afinnell/.jenkins found at: $user.home/.jenkins
[Winstone 2011/08/21 12:33:21] - HTTP Listener started: port=9494
Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
13

This worked for me for changing port to 7070 or other.

sudo defaults write /Library/Preferences/org.jenkins-ci httpPort 7070

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

More info about this

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
uopeydel
  • 431
  • 4
  • 22
5

I have installed Jenkins on my Mac OS High Sierra using Brew.

Please follow below steps:

  1. You have to change the port to below file:

    /usr/local/Cellar/jenkins/2.x.x/homebrew.mxcl.jenkins.plist

  2. Assign any free port like 7070 or any number you want.[If you have static IP then you can give port 80(HTTP)]

    --httpPort=7070

  3. You also need to restart the Jenkins Server. using below brew service commands:

    $ brew services stop jenkins

    $ brew services start jenkins

That's all.!

Pratik Patel
  • 2,209
  • 3
  • 23
  • 30
  • This is the solution for me, especially because /Library/Preferences/org.jenkins-ci doesn't exist for me. I think it's since the new security model of OSX (>= High Sierra) – Luc Bloom Jun 23 '21 at 11:31
  • Also, if you are not proficient in vim/vi/nano and can't find it through Finder, you can use BBEdit's "Open file from path..." feature to edit the above file (after you deducted the actual path from the Terminal). – Luc Bloom Jun 23 '21 at 11:32
  • Be aware that if you installed `jenkins-lts`, you will need to reference it as such and not simply as `jenkins`. This applies both to where the configuration file is stored and to the name of the service when restarting it – Fearnbuster Aug 16 '21 at 17:45
1

Just write the following command in the terminal:

sudo defaults write /Library/Preferences/org.jenkins-ci.plist httpPort 9999

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist

sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

That should resolve it.

Maaz Hasan
  • 11
  • 2
0

An other solution in case of running two daemons of Jenkins, on different HTTP ports (i.e. 7070 and 7071) : Multiple Jenkins daemons on different HTTP ports (Mac OS X)

Community
  • 1
  • 1
Stéphane B.
  • 3,260
  • 2
  • 30
  • 35