一、前置条件
内网部署Jenkins,并安装好所需插件
此篇内容需承接内网搭建Jenkins自动化远程部署项目到Windows服务器_jenkins内网安装-CSDN博客
,才更好操作与理解
二、在Jenkins中创建项目
三、配置项目
General
Source Code Management
Build Environment
Build
#!/bin/sh -l
git checkout $tag
dotnet restore
dotnet build
dotnet publish "/root/.jenkins/workspace/xxx/services/host/xxx.Host" -c JKdeploy
echo "开始打包成一个文件"
tar -cvf publish.tar services/host/xxx.Host/bin/JKdeploy/net6.0/publish/
四、执行构建
五、目标服务器需要做的
创建批处理程序
@echo offset BUILD_ID=DONTKILLME
set port=44315
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do taskkill /pid %%m -t -fsetlocalREM Setting environment variables
set "tarFile=D:\QIU\jenkins_ci_cd\xxx\publish.tar"
set "extractFolder=D:\QIU\jenkins_ci_cd\xxx"REM Download and unzip tar
tar -xf %tarFile% -C %extractFolder%REM Check whether the decompression is successful
if errorlevel 1 (echo Decompression failureexit /b 1
)REM Run DLL file
cd /d %extractFolder%\services\host\xxx.Host\bin\JKdeploy\net6.0\publish
dotnet xxx.Host.dll --urls "http://x.x.x.x:44315" --environment JKdeployendlocal