Skip to content

Instantly share code, notes, and snippets.

@ssmythe
Created April 4, 2016 21:40
Show Gist options
  • Save ssmythe/c69fa652a5c98d2356f28328be17405c to your computer and use it in GitHub Desktop.
Save ssmythe/c69fa652a5c98d2356f28328be17405c to your computer and use it in GitHub Desktop.
install-jenkins-2.0-centos6.sh
#!/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: download RPM"
wget -O /tmp/jenkins-2.0-1.1.noarch.rpm http://pkg.jenkins-ci.org/redhat-rc/jenkins-2.0-1.1.noarch.rpm
echo "jenkins: Install Jenkins"
yum -y localinstall /tmp/jenkins-2.0-1.1.noarch.rpm
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