Centos7安装Jenkins脚本一键部署
公司原先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
测试结果如下:
安装成功
原文地址:https://blog.csdn.net/weixin_66575196/article/details/143888559
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!