jenkins中xshell指令碼切換root使用者
阿新 • • 發佈:2019-02-01
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