Initial commit

This commit is contained in:
Benjamin Muschko
2019-11-17 16:40:48 -07:00
commit 248499c8f6
108 changed files with 994 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
(1..2).each do |number|
config.vm.define "jenkins-agent-#{number}" do |node|
node.vm.network "forwarded_port", guest: 22, host: "909#{number}"
node.vm.network "private_network", ip: "192.168.99.20#{number}"
node.vm.hostname = "jenkins-agent-#{number}"
end
end
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provision "shell", inline: <<-SHELL
sudo add-apt-repository ppa:openjdk-r/ppa -y
sudo apt-get update
sudo apt-get -y install openjdk-8-jdk
sudo update-alternatives --config java
sudo apt-get -y install git
sudo useradd -m jenkins
echo "jenkins:jenkins" | sudo chpasswd
sudo keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt
sudo mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts
sudo /var/lib/dpkg/info/ca-certificates-java.postinst configure
SHELL
end

View File

@@ -0,0 +1,17 @@
# Exercise 10
You will start a VM using Vagrant as practice environment to set up a distributed build with 2 agents.
## Configuring and Executing Jobs in a Distributed Build
1. Go to "Manage Jenkins" > "Manage Nodes". You should see a single `master` node.
2. Configure the `master` node by setting the # of executor value to 0. That will take care of never using the `master` for job workload.
3. Have other physical or virtual machines ready that can act as agent nodes. Log into the machine as `root` user and create a new user named `jenkins` with the commands `useradd -d /var/lib/jenkins jenkins` and `passwd jenkins`. From the `master` node, copy the contents of the `id_rsa.key` file to the clipboard. Paste the contents of the clipboard to the file `/var/lib/jenkins/.ssh/authorized_keys`.
4. Add new nodes by clicking "New Nodes". Enter an appropriate name and select the option "Permanent Agent". Use the remote directory `/home/jenkins/jenkins_slave` and set the # of executors to 2. Enter the host and provide credentials by selecting "SSH Username with private key". To keep things easy select "Non verifying Verification Strategy".
4. Trigger a build. You should see that the build is only executed on the agent and not the `master` node.
5. Add at least one more agent.
6. Trigger a build. You should see that the build can be executed on any of the agents.
7. Configure one of the agents to only build jobs with a specific label e.g. `java`. Change the "Usage" field to "Only build jobs with label expressions matching this node".
8. Configure the `gradle-initializr` job and assign the label `java`.
9. Trigger a build of the `gradle-initializr` job. It is only executed by the dedicated agent.
10. Trigger other jobs that do not have the label `java` assigned to them. They are waiting for an agent that can execute the build.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1006 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@@ -0,0 +1,29 @@
# Solution
Configure the `master` node.
![Master Configuration](./images/master-config.png)
Add a new agent node.
![Agent Configuration](./images/agent-config.png)
You will see that the `master` node isn't even listed anymore in the executor overview.
![Node Overview](./images/node-overview.png)
Reconfigure the agent node to only build jobs with a specific label.
![Agent Label Configuration](./images/agent-label-config.png)
Reconfigure the job to only use agents that can handle a specific label.
![Job Label Configuration](./images/job-label-config.png)
A build of the job is now only handled by an agent with the assigned label.
![Build For Labeled Agent](./images/build-for-label.png)
Other jobs sit in a queue waiting for an agent that can handle the execution criteria.
![Build For Labeled Agent](./images/queued-job.png)