一、官网安装办法 https://pkg.jenkins.io/redhat-stable/
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install jenkins
二、自动安装(包括清理旧版、开机启动、获取首次登录密码等,推荐)
安装:下载 jenkins.rar , 按照readme操作即可
贴出shell文件:
#!/bin/sh
#关闭进程
killpids(){
pids=($(ps -ef | grep $1 | awk '{print $2}'))
for pid in ${pids[@]}; do
echo "关闭进程: pid ${pid}"
kill -9 ${pid}
done
}
killpids jenkins
#uninstall old jenkins
old_jenkins=($(rpm -qa|grep jenkins))
for((i=0; i<${#old_jenkins[@]}; i++));do
echo "旧版jenkins: ${old_jenkins[i]}"
echo "删除..."
yum -y remove jenkins ${old_jenkins[i]}
done
#删除
rm -rf /etc/logrotate.d/jenkins
rm -rf /etc/rc.d/init.d/jenkins
rm -rf /etc/sysconfig/jenkins
rm -rf /usr/lib/jenkins
rm -rf /var/log/jenkins
rm -rf /var/cache/jenkins
rm -rf /var/lib/jenkins
rm -rf /tmp/winstone/jenkins.war
#install jenkins
srcPath=$(find /usr/jenkins -maxdepth 1 -type f|grep '.*jenkins.*.rpm$')
if [[ $srcPath =~ "jenkins" ]]
then
echo "安装包:$srcPath"
rpm -ivh $srcPath
else
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum -y install jenkins
fi
#修改端口号
sed -i 's/JENKINS_PORT=\"8080\"/JENKINS_PORT=\"8080\"/' /etc/sysconfig/jenkins
#启动并查看状态
service jenkins start
service jenkins status
#开机启动
echo ""
echo "开机启动"
chkconfig jenkins on
#修改端口号
echo "修改端口号: JENKINS_PORT="8080""
#显示版本
echo "version:"
rpm -qa|grep jenkins
#Administrator password(首次打开确认密码)
function getPassword(){
spin=('. ' '.. ' '... ' '....')
cnt=0
while(true)
do
((cnt++))
echo -n " wait${spin[$((cnt % 4))]}"
echo -n -e \\r
sleep 0.2
if [[ $cnt -gt 180 ]]
then
echo -e "\e[1;31mERROR:\e[0m Read Password Failure"
break
fi
if [ -f "/var/lib/jenkins/secrets/initialAdminPassword" ]
then
grep '' /var/lib/jenkins/secrets/initialAdminPassword
break
fi
done
}
echo "Administrator password(首次打开确认密码):"
getPassword
echo ""