首页
登录 | 注册

jenkins中xshell脚本切换root用户

jenkins执行脚本中如果切换用户:

注意红色部份【每句添加 ; 分号】

======================

#!/bin/bash
SERVER=http://10.82.0.103:8081/ #jenkins服务器地址  
JENKINS_USER=admin #jenkins用户  
JENKINS_PWD=admin123 # jenkins用户密码  
MAVEN_NAME=com.cci.market #maven项目pom.xml的groupId  
MAVEN_VERSION=1.0.0 #maven项目pom.xml的version  
APPLICATION_NAME=commerce #应用名称,docker容器,文件夹,JOB名,统一使用这个
IMAGE_NAME=$APPLICATION_NAME:latest #镜像名
su - root <<EOF # 切换root用户
echo "下载jar文件......";
curl -s --user $JENKINS_USER:$JENKINS_PWD -#  "$SERVER/job/$APPLICATION_NAME/ws/target/$APPLICATION_NAME.jar" -o /datadisk//docker/$APPLICATION_NAME/$APPLICATION_NAME.jar;
echo "下载dockerfile文件......";
curl -s --user $JENKINS_USER:$JENKINS_PWD -#  "$SERVER/job/$APPLICATION_NAME/ws/Dockerfile" -o /datadisk//docker/$APPLICATION_NAME/Dockerfile;
echo "下载完成!";
CURRENT=`pwd`;
echo "停止对应的docker容器";
docker stop $APPLICATION_NAME;
echo "删除停止的容器";
docker rm  $APPLICATION_NAME;
echo "删除老镜像";
docker rmi $IMAGE_NAME;
echo "重新build镜像";
docker build -t $IMAGE_NAME /datadisk/docker/$APPLICATION_NAME;
echo "重启项目...";
docker run --name $APPLICATION_NAME  -v /etc/localtime:/etc/localtime  -d  -p 8080:8080 --link myredis:redis --link mymysql:mysql    -v /data/summary:/summary -v /usr/local/cci/files/:/usr/local/cci/files/  -v /certificates:/certificates -v /datadisk/docker/logs/$APPLICATION_NAME-logs:/datadisk/logs/service/$APPLICATION_NAME/  $IMAGE_NAME java -jar -Dfile.encoding=UTF8 -Duser.timezone=GMT+08  --spring.cloud.config.profile=dev   -Xmx1000m /datadisk/docker/$APPLICATION_NAME/$APPLICATION_NAME-$MAVEN_VERSION.jar;
exit;
echo "项目启动成功.";
EOF

 

 



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.008 s.
京ICP备10005923号