windows+jenkins+iis 部署
1.安装jenkins
下载地址:https://www.jenkins.io/download/
2.需要配置java环境
配置教程:https://www.cnblogs.com/liuxiaoji/p/5729124.html
3.初始化jenkins配置目录 注:为什么要修改工作目录 因为默认工作目录在C盘 后续配置项目编译,发布可能会有权限问题
1.打开jenkins安装目录
2.新建文件夹 work
3.打开jenkins.xml 配置文件
4.将%LocalAppData%替换成你的 work文件夹目录
5.重启jenkins服务
6.http://localhost:8080 重新访问这个地址 这时候jenkins 会重新初始化工作目录
4.jenkins 插件安装
1.先安装推荐插件
2.Gitlab Hook、Build Authorization Token Root、Publish Over SSH、Gitlab Authentication、Gitlab、Git Parameter
3.添加完插件重启jenkins
5.新建项目
项目名称命名
参数配置
git源代码管理配置
jenkins 是git账户 需要拥有维护者级别的项目权限
下面是代码发布部署脚本配置
echo "进入目录"
cd src\Benchint.PublicHealth.Manager.HttpApi.Host
echo "还原项目包"
dotnet restore
echo "编译代码"
dotnet build -c "%COMPILE_MODE%"
echo "停止IIS站点"
C:\Windows\System32\inetsrv\appcmd.exe stop site "Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe stop appPool /appPool.name:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
echo "发布项目"
dotnet publish -c "%COMPILE_MODE%" -o "E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\service"
echo "新建版本号"
md "E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\%MAJOR_NO%.%BUILD_NO%.%BUILD_ID%"
echo "拷贝项目到当前版本"
xcopy E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\service E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\%MAJOR_NO%.%BUILD_NO%.%BUILD_ID% /s/e/y
echo "拷贝配置文件"
xcopy E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\config E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\%MAJOR_NO%.%BUILD_NO%.%BUILD_ID% /s/e/y
echo "删除站点"
C:\Windows\System32\inetsrv\appcmd.exe delete site "Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe delete apppool "Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
echo "新建站点"
C:\Windows\System32\inetsrv\appcmd.exe add site /name:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature" /bindings:http://10.3.1.245:5038 /physicalpath:"E:\Feature\Benchint.PublicHealth.Manager.HttpApi.Host\%MAJOR_NO%.%BUILD_NO%.%BUILD_ID%"
C:\Windows\System32\inetsrv\appcmd.exe add AppPool /name:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe Set app "Benchint.PublicHealth.Manager.HttpApi.Host.Feature/" /applicationpool:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe set apppool /apppool.name:Benchint.PublicHealth.Manager.HttpApi.Host.Feature /managedRuntimeVersion:""
echo "启动项目"
C:\Windows\System32\inetsrv\appcmd.exe start site "Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe start appPool /appPool.name:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
C:\Windows\System32\inetsrv\appcmd.exe recycle appPool /appPool.name:"Benchint.PublicHealth.Manager.HttpApi.Host.Feature"
编译如果提示nuget 不存在则在工作目录新建 nuget.config文件
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="bechint" value="http://10.3.1.240:8080/nuget" /> </packageSources> </configuration>
配置gitlab push代码自动发布
#首先,你得有一个代码仓库,赶紧到gitlab上创建一个,然后创建个分支并创建一个文件。
#配置gitlab,当有代码提交时,触发jenkins的部署操作
进行GitLab + Jenkins 自动化部署时,在GitLab的 MyProject => Settings => Integrations中输入完 "URL" 和 “Secret Token”,点击按钮 “Add webhook”时,报错如下:
这时候需要对gitlab 设置白名单
进入 Admin area => Settings 直接就能看到如下
添加对应jenkisn服务的IP
提交代码测试