公司原先Jenkins二进制安装,自己闲来无事在测试主机优化了一下,一键部署,jenkins2.426版本+jdk11版本
#!/bin/bash
jenkins_file="jenkins-2.426.3-1.1.noarch.rpm"
# 更新软件包列表
echo "更新软件包列表..."
sudo yum update
# 检查Java是否已安装
if java -version &>/dev/null; then
echo "Java已安装,跳过此步骤。"
else
echo "安装Java 11..."
sudo yum install java-11-openjdk
fi
if rpm -aq |grep jenkins; then
echo "Jenkins已安装,跳过安装步骤。"
else
echo "安装Jenkins..."
sudo rpm -ivh $jenkins_file
chown -R jenkins:jenkins /usr/bin/jenkins
fi
# 启动并启用Jenkins服务
if systemctl is-active --quiet jenkins; then
echo "Jenkins服务正在运行,跳过启动。"
else
echo "启动Jenkins服务..."
sudo systemctl start jenkins
fi
if systemctl is-enabled --quiet jenkins; then
echo "Jenkins服务已设置为开机启动。"
else
echo "设置Jenkins服务为开机启动..."
sudo systemctl enable jenkins
fi
# 输出Jenkins的初始管理员密码
if [ -f /var/lib/jenkins/secrets/initialAdminPassword ]; then
echo "Jenkins安装完成!"
echo "初始管理员密码如下:"
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
else
echo "Jenkins尚未成功安装或未能生成初始管理员密码。"
fi
测试结果如下:
安装成功