Created
September 19, 2015 13:17
-
-
Save yan-foto/9a1b7b967832ad938f89 to your computer and use it in GitHub Desktop.
Vagrant shell provision to solve `No X-Jenkins-CLI2-Port` (Ubuntu guest)
This file contains 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
#!/bin/bash | |
# This is a simple example of a shell script which is used as a Vagrant provision | |
# It can be used as: 'config.vm.provision "shell", path: "./jenkins.sh"' | |
# inside a Vagrantfile. | |
# The logic is simple and the implementation as well. Any suggestions/improvements | |
# are highly welcome. | |
# Default values | |
jenkins_home="/var/lib/jenkins" | |
jenkins_url="http://localhost:8080" | |
echo "Adding jenkins key..." | |
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - | |
echo "Adding jenkins repository..." | |
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' | |
echo "Installing jenkins..." | |
sudo apt-get update | |
sudo apt-get install -y jenkins | |
echo "Starting Jenkins..." | |
sudo service jenkins start | |
# Make sure CLI jar is created | |
echo "Waiting 5 seconds to have jenkins CLI initiated..." | |
sleep 5 | |
jenkins_cli=$(sudo find / -type f -name 'jenkins-cli.jar' -print0) | |
echo "Jenkins CLI found at $jenkins_cli" | |
# Checking if server is up and running | |
sleep_interval=1 | |
while true; do | |
st=$(curl -sL $jenkins_url/cli -w "%{http_code}" -o /dev/null) | |
if [ "$st" != "200" ]; then | |
echo "Jenkins server CLI not responding (status: '$st'). Sleeping $sleep_interval seconds..." | |
sleep $sleep_interval | |
((sleep_interval++)) | |
else | |
break | |
fi | |
done | |
# Update jenkin's update center :/ | |
echo "Update center gettign up-to-date!" | |
sudo mkdir -p $jenkins_home/updates | |
wget http://updates.jenkins-ci.org/update-center.json -qO- \ | |
| sed '1d;$d' > $jenkins_home/updates/default.json | |
# An example of using CLI | |
echo "Installing git plugin..." | |
sudo java -jar "$jenkins_cli" -s "$jenkins_url" install-plugin git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The loop starting on line 33 solves the following problem:
In an incremental probe-wait loop it waits until the CLI is up and running.