Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up jenkins slave on Mac OS

I'm confused about setting up Jenkins slave on Mac. Google seems to have a great answer for java web start option (https://blog.codecentric.de/en/2012/01/continuous-integration-for-ios-projects-with-jenkins-ci/), however can someone clarify steps for setting up jenkins slave on mac with ssh start option.

Currently jenkins master is on Centos. As I understood, to make a slave on Mac you should: 1. Go to Mac and create a new full-fledged sudo user for jenkins with home folder where agent itself will reside. 2. Set up node as ususal linux node in Jenkins web interface with login|pass for this user. 3. Restrict your mac build to this node.

However I'm not sure if first step is right - do i need to set up jenkins user by hand with elevated privileges, ability to log onto machine, etc. Perhaps it's possible to create a "hidden" user - if that is so, can someone help or point to good manual for this? I'm new to mac terminal, so not sure if steps all the same as linux or different.

Thank you.

like image 369
user2541436 Avatar asked Mar 15 '14 12:03

user2541436


People also ask

How do I add a slave to a Jenkins VM?

To add your VM as a node in Jenkins, go to the Manage Jenkins panel and select Manage Nodes. Provide a name for the node, select Permanent Agent, and then click OK. For the Remote root directory, provide /var/lib/jenkins . This is the default directory where Jenkins creates its workspace.

Which option is used to configure slaves in Jenkins?

The Labels for which the name is entered as “Slave1” is what can be used to configure jobs to use this slave machine. Select Usage to Use this node as much as possible. For launch method we select the option of “Launch agent by connecting it to the master”.


2 Answers

Just finished setting up my Mac mini slave for ssh access. Lots of old tutorials and ones with unnecessary information. I had to reboot my mini to start over again and this time it worked.

To put it quickly (this is all through terminal/command line, no Ubuntu nothing else):

  1. Create ssh private and public keys with ssh-keygen. In my case keys were given to me with -C "name" but no passphrase and with file names of id_rsa and id_rsa.pub. Keep private (non .pub) key to be used by Jenkins Credentials later and for testing purposes while verifying things are working for ssh connection without having to relaunch Jenkins agent, the private key should be kept in the /Users/<username>/.ssh directory and readable permission and ownership of the user of local test host if that's how I'm testing it

  2. mkdir .ssh in remote Mac mini slave's /User/jenkins/ directory

  3. on Mac mini make sure owner of .ssh directory and any sub directories or files are jenkins and NOT root (sudo chown ...).

  4. make sure permissions of .ssh directory and any sub dirs or files are read and writeable (if you haven't set ownership properly, in order to change permissions you will be required to use sudo. If you are using sudo to set permissions, you haven't properly set ownership to the jenkins user)

  5. allow remote login in the Mac mini system preferences -> Sharing -> check Remote login and allow Administrators and static IP -> Network -> TCP/IP -> DHCP with manual or completely manual

  6. on test host/local machine (non Mac mini) terminal and command line ssh [email protected] to make sure you can ssh into remote Mac mini with password authentication. You may get a request to okay the new host (at remote Mac mini's IP address).

  7. then logout and in local machine use ssh-copy-id -i to copy contents of id_rsa.pub (whether its in .ssh or wherever) to authorized_keys found here.

  8. this will automatically generate authorized_keys file in .ssh directory

  9. make sure authorized_keys file is also of proper permission

  10. in Jenkins manage nodes. Create a new node. Add credential and make it ssh username with private key. Username: jenkins. Private key: enter directly. String should be copied from local machine test host private key (pbcopy<~/.ssh/id_rsa) including the ==== begin and end private key ====== parts and then save.

  11. Then on new node configuration No need for toolkit. Remote root directory: /Users/jenkins. Host: Mac mini's static IP address. Host Key verification strategy: Manually Trusted Key verification strategy. Check require manual verification of initial connection

  12. upon first connection attempt if you don't have JDK setup and running then do so. I downloaded Java 8 Stack Exchange Development Kit and once I confirmed it was installed on Mac mini with javac-version and java-version I launched agent again and authenticated no problem.

My mistakes from reading old tutorials were:

trying to remove the need for passwords in /etc/ssh/sshd_config. This was completely unnecessary Also, I may have not paid attention to the owner and/or screwed up permissions of .ssh, .ssh/authorized_keys & .ssh/id_rsa in remote and my local machine as well.

Initially I deleted the ===== Begin private key and ======End private key when I manually entered the private key when creating the credential in jenkins. Those should be included. The file of id_rsa should be left as is.

like image 103
SpicyNinja1010 Avatar answered Sep 23 '22 01:09

SpicyNinja1010


You do need a user on the Mac which the Jenkins master will use to ssh in. But this is exactly the same as setting up a Linux slave.

Whether the user needs elevated privileges depends on what you want Jenkins to do with the account.

You also need to log into Mac from the console using an admin user and turn on remote login in the Sharing panel of System Preferences. In the same panel you can restrict the remote login to specific users or allow all users to log in.

If I were you, I would create a normal user for Jenkins using the Users and Groups panel in System Preferences. Creating a hidden user using command line tools is possible, but it is a bit involved. If you really want to go there, you can check how postinstall script in Jenkins Mac installer creates a user named jenkins:

https://github.com/jenkinsci/packaging/blob/master/osx/scripts/postinstall-launchd-jenkins

like image 31
sti Avatar answered Sep 23 '22 01:09

sti