-
-
Save zenoando/78bd701deec41edfd12f to your computer and use it in GitHub Desktop.
jenkins-slave.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is how you add a Jenkins slave | |
# On master, create ssh keys for the Jenkins user if you don't have one. | |
# We will use ssh-key auth for master connections towards the slave. | |
sudo -u jenkins -H ssh-keygen | |
# On slave. | |
# Create a jenkins user account | |
# Create a system directory and use that for jenkins' user home directory | |
# Create a ssh directory on jenkins' user home and add in the master's public ssh key file in authorized_keys. | |
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /bin/bash jenkins-slave | |
install -d -o jenkins -g jenkins /var/lib/jenkins | |
install -d -m 700 -o jenkins -g jenkins /var/lib/jenkins-slave/.ssh | |
cat jenkins.master.rsa.pub >> /var/lib/jenkins/.ssh/authorized_keys | |
# On master | |
sudo -u jenkins -H ssh [email protected] | |
# remember the host key | |
# Now you can add an SSH slave through the Jenkins web UI, it'll download all the Java .jars automatically | |
# (you may need to sudo apt-get install openjdk or something on the slave machine) | |
# To allow the slave to get access to git repos on mygitserver, run this on the slave machine: | |
sudo -u jenkins-slave -H ssh-keygen | |
# On mygitserver | |
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /usr/bin/git-shell jenkins-slave | |
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave | |
install -d -m 700 -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave/.ssh | |
vi /var/lib/jenkins-slave/.ssh/authorized_keys | |
copy /var/lib/jenkins-slave/ssh/id_rsa.pub from the slave machine | |
# On slave | |
sudo -u jenkins-slave -H ssh mygitserver | |
# remember the host key | |
sudo -u jenkins-slave -H git config --global user.name 'Jenkins' | |
sudo -u jenkins-slave -H git config --global user.email '[email protected]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment