Skip to content

Instantly share code, notes, and snippets.

@ssmythe
Created February 22, 2016 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssmythe/bfed8846c1489ecedb70 to your computer and use it in GitHub Desktop.
Save ssmythe/bfed8846c1489ecedb70 to your computer and use it in GitHub Desktop.
Install Jenkins on CentOS6
#!/usr/bin/env bash
#
# JAVA OPENJDK
#
echo "jenkins: Install Java"
# https://issues.jenkins-ci.org/browse/JENKINS-31102
yum -y install java-1.8.0-openjdk
echo "jenkins: Displaying system Java version"
java -version
#
# JENKINS
#
echo "jenkins: Install jenkins.repo"
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
echo "jenkins: Install Jenkins"
yum -y install jenkins-1.642.1
echo "jenkins: Setting jenkins user shell to BASH"
chsh -s /bin/bash jenkins
#
# JENKINS USER SUDO
#
echo "jenkins: adding jenkins to sudoers file"
chage -I -1 -m 7 -M -1 -E -1 jenkins
if ! grep -q '^#includedir /etc/sudoers.d' /etc/sudoers; then
mkdir -p /etc/sudoers.d
chmod 0750 /etc/sudoers.d
echo '#includedir /etc/sudoers.d' >> /etc/sudoers
fi
echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/jenkins
chmod 0440 /etc/sudoers.d/*
#
# START JENKINS
#
echo "jenkins: Start Jenkins service"
/sbin/service jenkins start
echo "jenkins: Verifying Jenkins is running"
sleep 2
COUNTER=0
grep -q 'Jenkins is fully up and running' /var/log/jenkins/jenkins.log
while [[ $? -ne 0 && $COUNTER -lt 60 ]]; do
sleep 2
let COUNTER+=2
echo "Waiting for Jenkins to initialize... ($COUNTER seconds so far)"
grep -q 'Jenkins is fully up and running' /var/log/jenkins/jenkins.log
done
if [[ $(grep -q 'Jenkins is fully up and running' /var/log/jenkins/jenkins.log) -eq 0 ]]; then
echo "jenkins: Jenkins is running"
else
echo "jenkins: ERROR: Jenkins is NOT running. Something went wrong."
exit 1
fi
# Check main page is loading
echo "jenkins: Verifying Jenkins main page is loading"
sleep 2
COUNTER=0
curl -sSL http://localhost:8080 | grep -q "Welcome to Jenkins!"
while [[ $? -ne 0 && $COUNTER -lt 60 ]]; do
sleep 2
let COUNTER+=2
echo "Waiting for Jenkins main page to load... ($COUNTER seconds so far)"
curl -sSL http://localhost:8080 | grep -q "Welcome to Jenkins!"
done
if [[ $(curl -sSL http://localhost:8080 | grep -q "Welcome to Jenkins!") -eq 0 ]]; then
echo "jenkins: Jenkins main page is loading"
else
echo "jenkins: ERROR: Jenkins main page is NOT loading. Something went wrong."
exit 1
fi
#
# REFRESH UPDATE CENTER DATA
#
cat - > /tmp/refresh_update_center.groovy <<EOF
import jenkins.model.*
import java.util.logging.Logger
def logger = Logger.getLogger("")
logger.info("Refreshing update center data: start")
def instance = Jenkins.getInstance()
def uc = instance.getUpdateCenter()
uc.updateAllSites()
logger.info("Refreshing update center data: done")
EOF
chown jenkins:jenkins /tmp/refresh_update_center.groovy
chmod 644 /tmp/refresh_update_center.groovy
echo "jenkins: Refreshing update center data"
su -l -c "java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 groovy /tmp/refresh_update_center.groovy" jenkins
#
# PLUGINS
#
echo "jenkins: Installing plugin: greenballs"
su -l -c "java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080 install-plugin greenballs" jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment