.net core jenkins持续集成
执行 Shell
pwd ls echo ${PATH} whoami which dotnet dotnet --info dotnet --version echo '============================begin restore=======================================' dotnet restore echo '============================begin build=========================================' #dotnet build -c:Release --no-incremental rm -rf ${WORKSPACE}/jenkins_publish mkdir ${WORKSPACE}/jenkins_publish dotnet publish -r centos.7-x64 -c:Release -o ${WORKSPACE}/jenkins_publish #把服务启动脚本拷贝到打包目录 if [ ! -f "${WORKSPACE}/jenkins_publish/project.service" ]; then touch ${WORKSPACE}/jenkins_publish/project.service #echo "123" > ${WORKSPACE}/jenkins_publish/project.service #生成启动服务 echo "[Unit] Description=.NET Core ProjectService [Service] WorkingDirectory=/data/dotnet_web/${JOB_NAME} ExecStart=/usr/bin/dotnet /data/dotnet_web/${JOB_NAME}/Web.dll Restart=always RestartSec=10 SyslogIdentifier=ProjectApp User=root Environment=ASPNETCORE_ENVIRONMENT=Test [Install] WantedBy=multi-user.target" > ${WORKSPACE}/jenkins_publish/project.service fi echo '============================发布到服务器==========================================' #cp -r ${WORKSPACE}/jenkins_publish/* /home/netcore/project/ #创建打包路径,并对当前代码进行打包 if [ ! -d "${WORKSPACE}/tar" ]; then mkdir -p ${WORKSPACE}/tar fi #清空tar目录下文件 rm -rf ${WORKSPACE}/tar/${JOB_NAME}-*.tar.gz cd ${WORKSPACE}/jenkins_publish tar -zcf ${WORKSPACE}/tar/${JOB_NAME}-${BUILD_ID}.tar.gz ./* --exclude=./tar --exclude=./.git --exclude=./.gitignore
SSH Publishers
#创建项目版本目录 if [ ! -d "/data/release/${JOB_NAME}/${BUILD_ID}" ]; then mkdir -p /data/release/${JOB_NAME}/${BUILD_ID} fi #解压包 tar -zxf /data/release/${JOB_NAME}/${JOB_NAME}-${BUILD_ID}.tar.gz -C /data/release/${JOB_NAME}/${BUILD_ID}/ --exclude=./.git* #删除压缩包 rm -rf /data/release/${JOB_NAME}/${JOB_NAME}-${BUILD_ID}.tar.gz #更新web软连接 rm -rf /data/dotnet_web/${JOB_NAME} ln -sf /data/release/${JOB_NAME}/${BUILD_ID} /data/dotnet_web/${JOB_NAME} #修改站点属主和权限 chown root:root -R /data/dotnet_web/${JOB_NAME}/ #删除/data/release 下的多余版本目录(默认设置保留2版) cd /data/release/${JOB_NAME}/ if [ "ls /data/release${JOB_NAME}/ | wc -l" > "${keep_num}" ]; then ls -lt | awk '{if($9<=("${BUILD_ID}"-"${keep_num}")){print $9}}' | xargs rm -rf fi #部署启动服务 if [ ! -f "/usr/lib/systemd/system/project.service" ]; then cp /data/dotnet_web/${JOB_NAME}/project.service /usr/lib/systemd/system/ fi systemctl restart project.service