Jenkins 操作
1) Jenkins 具体安装略, 傻瓜式下一步... 安装完成. 下载见官方网站: https://jenkins.io/download/ , 找到 downlaod 下载, 这里项目基于. Net Freamwork,Jenkins 中构建需编译. net 程序, 方便编译, 选择安装 Windows 版本.
这里 Jenkins 安装前, 需配置好 JDK 环境.
2) 插件安装
Jenkins 安装好后, 进入系统管理 ->插件管理, 安装好 Msbuild,Git,ftp
3) 新建 Job
4) Job 设置
设置保留构建的天数, 和构建最大数量
自定义 workspace 工作空间
5) 获取 Git 仓库代码
指定 Git 仓库代码项目分支, 这里为测试环境, 统一使用 dev 分支构建.
主要有以下配置项:
Repositories URL:Git 方式获取代码路径, 走 SSH 协议.
Credentials: 授权登录信息, 添加凭据. 这里使用 SSH 方式 (用户名 + 私钥方式) 登录. 需先 Jenkins 配置 SSH 方式登录 GitLab.
Branches to build: 指定分支.
6) 构建程序配置
6.1 安装插件后, 进入系统管理 ->Global Tool Configuration, 找到 MSbuild 配置选项.
这里 Path to MABuild 配置 VS 下的 MSBuild. 不使用 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.
6.2 构建前从 GitLab 中拉取项目 config 配置和 Nuget 依赖. 创建 Windows batch command.
创建的 Windows batch command 如下:
- cd /d E:\Git-config\config-public
- Git pull
- xcopy E:\Git-config\config-public\TEST E:\Publish-web /s /e /h /y /exclude:E:\Git-config\config-public\excld.txt
从 Git config 目录下 copy 配置文件到项目中, 其中 exclude 配置指定无需 copy 的文件, 如隐藏的. gitkeep 文件等.
6.3 安装配置 Nuget, 解决项目文件依赖, 获取程序需要的包.
E:\Program Files (x86)\Tools\nuget.exe"restore"E:\jenkins-workspace\APIDatatest\BM.BMData.Web\BM.BMData.sln
7) 构建
选择 "Build a Visual Studio project or solution using MSBuild" 配置如下:
MSBuild Version: 之前 Global Tool Configuration 中配置的版本.
MSBuild Build File: 要构建的解决方案 sln 文件, 也可以是项目. csproj 文件. 注意都是相对工作的路径.
Command Line Arguments:
/t:Rebuild 重新生成
/p:Configuration=Debug 生成 Debug 模式
/t:resolveReferences
/p:WebProjectOutputDir="E:\Publish-web\APIData-Test\web" 构建后 sln 输出目标目录
/p:OutputPath="E:\Publish-web\APIData-Test\web\bin" 输出目标的 bin 目录
配置完成后, 点击构建
8) 构建后操作
来源: http://www.bubuko.com/infodetail-3301130.html