以下是重构后的代码:
```bash
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt install openjdk-17-jdk
sudo apt-get install -y jenkins
systemctl status jenkins
# 获取密码
cat /var/lib/jenkins/secrets/initialAdminPassword
# 启动、重启和停止Jenkins服务
service jenkins start
service jenkins restart
service jenkins stop
```