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