自学内容网 自学内容网

linux系统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页面操作

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


原文地址:https://blog.csdn.net/qq_59207739/article/details/136414997

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!