通过Jenkins和GitBlit联合完成半自动化部署
服务器需要安装相应的环境
Git环境
DotNET6运行时环境
DotNET6编译环境SDK
JDK11
Jenkins安装包
首先打开教程安装GitBlit并配置Java环境
安装DotNET6运行时环境和SDK,并安装Git
通过官方安装Jenkins流程进行安装
所有环境搭建完毕访问所配置的端口进入Jenkins安装系统推荐插件,进入系统并修改管理员密码
新建项目,选择Freestyle project

选择源码管理Git输入Git仓库地址并设置分支
因为GitBlit和Jenkins都是在同一服务器所以我用私网IP

创建Credentials也就是Git用户信息不然无法拉取代码(只需要填写账号和密码)

拉到倒数第二个构建,选择执行Windows cmd命令

输入以下命令
dotnet restore --还原
dotnet build --编译
C:\Windows\System32\inetsrv\appcmd.exe stop site "DotNET6API" --停止IIS中的指定网站
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:"DotNET6API" --停止IIS中的指定应用程序池
dotnet publish -o "C:\WebFile\DotNET6API" --将编译文件发布到指定目录下
C:\Windows\System32\inetsrv\appcmd.exe start site "DotNET6API" --启动IIS中的指定网站
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:"DotNET6API" --启动IIS中的指定应用程序池
配置完成点击构建即可看到完成状态

注意事项(如果Git报错:Failed to connect to repository : Error performing command: git.exe ls-remote -h xxxxxxx HEAD)
说明Git.exe找不到对应地址,需要将Git绝对路径进行修改(输入服务器Git安装地址默认在C盘Program Files文件夹下)

