Jenkins参数化构建
web服务器
下载nginx
下载git
cd /usr/share/nginx
rm -rf html
git clone http://root:Qq123456@192.168.188.176/ximu/test-nginx.git
mv test-nginx/ html
jenkins服务器
下载ansible
编写主机清单
vim /opt/hosts
[nginx]
web服务器ip
编写脚本代码
vim ansible.sh
#/bin/bash
SERVICE_NAME=$1
SERVICE_STATUS=$2
GITLAB_CODE=$3
GITLAB_ID=$4
HOSTFILE=/opt/hosts
CMD="ansible -i $HOSTFILE $1"
if [ $SERVICE_NAME = "nginx" ];then
if [ $GITLAB_CODE = "pull" ];then
$CMD -m shell -a 'chdir=/usr/share/nginx/html git pull origin main'
elif [ $GITLAB_CODE = "reset1" ];then
$CMD -m shell -a 'chdir=/usr/share/nginx/html git reset --hard HEAD^'
elif [ $GITLAB_CODE = "reset2" ];then
$CMD -m shell -a 'chdir=/usr/share/nginx/html git reset --hard HEAD^^'
elif [ $GITLAB_CODE = "reset_id" ];then
$CMD -m shell -a "chdir=/usr/share/nginx/html git reset --hard $GITLAB_ID"
fi
if [ $SERVICE_STATUS != "none" ] ;then
systemctl $SERVICE_STATUS nginx
fi
fi
jenkins服务web页面操作