jenkins 一键部署

#!/bin/bash

# This Bash is used for deploy jenkins
# create by: xiaoming
# set -euxo pipefail

# 截至到写脚本的时候,jenkins只支持java 11 && java 17 ,本次使用java 17
cat > /etc/yum.repos.d/jenkins.repo << EOF
[jenkins]
name=Jenkins
baseurl=http://pkg.jenkins.io/redhat
gpgcheck=1
EOF

# 写入key验证
rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key

# 关闭防火墙
function stopAndDisableFirewall(){
    setenforce 0
    systemctl stop firewalld && systemctl disable firewalld
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
}


# deploy java && fontconfig
function deployJavaAndJenkins(){
    yum install -y fontconfig > /dev/null
    yum install -y https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-x64_bin.rpm > /dev/null
    yum install -y jenkins --nogpgcheck > /dev/null
}

# http://ftp.icm.edu.pl/packages/jenkins/plugins/cloudbees-folder/latest/cloudbees-folder.hpi

# 修改jenkins的配置文件,修改用户jenkins到root
function changeJenkinsUser(){
    sed -i 's/User=jenkins/User=root/g' /usr/lib/systemd/system/jenkins.service
    sed -i 's/Group=jenkins/Group=root/g' /usr/lib/systemd/system/jenkins.service
    systemctl daemon-reload
    systemctl restart jenkins
}

function start(){
    stopAndDisableFirewall
    deployJavaAndJenkins
    changeJenkinsUser
}

start

echo -e "jenkins登录地址为:$(hostname -I) \n登录端口为:8080"
echo "jenkins 初始密码为 $(cat /var/lib/jenkins/secrets/initialAdminPassword)"

你可能感兴趣的:(jenkins 一键部署)