Jenkins QuickStart

1.     什么是Jenkins?

Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:

1、持续的软件版本发布/测试项目。

2、监控外部调用执行的工作。

2.     Jenkins 运行环境?

JDK 1.5 以上的windows,linux系统中。

 

3.     本文档目的?

本文档讲解的是如何应用Jenkins 发布 TFS 中的Web项目。

4.     开始

1.      

2.      

3.      

4.      

1.     下载Jenkins

打开http://jenkins-ci.org/

点击右侧Download 中的 Native package  Windows 项.

 

2.     安装Jenkins

执行setup.exe 进行安装.

 

 

3.     下载 Nuget.exe

打开https://nuget.codeplex.com/releases

下载Nuget.exe 放置某目录中如D:\Nuget\

在该目录中新建内容如下的Nuget.Config文件

 

<?xml version="1.0"encoding="utf-8"?>

<configuration>

  <config>

   

  </config>

 <packageRestore>

    <addkey="enabled" value="True" />

    <addkey="automatic" value="True" />

  </packageRestore>

 <packageSources>

    <clear />

    <addkey="nuget.org" value="https://www.nuget.org/api/v2/" />

    <addkey="Microsoft and .NET"value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/"/>

    <addkey="sh.centaline.nuget" value="http:// 10.4.19.202/nuget" />

 </packageSources>

 <disabledPackageSources />

 <activePackageSource>

    <addkey="All" value="(Aggregate source)" />

 </activePackageSource>

</configuration>

 

 

 

4.     配置Jenkins

在浏览器在输入地址 http://localhost:8080 打开Jenkins Web Manager 进行配置工作。

 

1.      安装插件

打开https://wiki.jenkins-ci.org/display/JENKINS/Plugins

分别查找下载以下插件:

 

 

下载完后,打开http://localhost:8080 点击 系统管理 -> 插件管理 -> 高级

 

把下载好的msbuild.hpi,tfs.hpi 插件进行上传安装.

 

2.      配置MSBuild插件

 

按图配置MSBuild命令,可建多个进行版本环境区分.

 

3.      配置GIT插件

 

5.     新建Job

打开http://localhost:8080/

点击新建

 

 

 

 

按图进行相关设置,名称自定.

 

6.     Job设置

点击ok后进行 job设置

 

1.      源代码设置

找到源码管理 设置块进行相关设置

 

1.      TFS设置

 

按图进行要发布的项目相关设置.

 

2.      GIT设置

在Add按钮里设定好用户名和密码

3.Credential设置

前面git设置里面涉及的Credential设置同样可以在首页的Credentials里面单独设置

在其中的Stores scoped to Jenkins中的global里可以点击AddCredentials来增加用户凭证

单击Add Credentials出现git 设置里面类似的配置对话框

2.      构建设置
2.1 找到构建 块进行构建,新建

 

 

两步骤后进行设置.

 

 

 

其中 batch command 主要的作是使用nuget 获取项目所需的dll,

 

命令格式如下:

Nuget.exerestore "项目.sln" -Config nuget.config

 

Msbuild 主要配置构建发布的Web项目,其中CommandLine Arguments填写如下

/t:ResolveReferences;Compile/t:_WPPCopyWebApplication /p:Configuration=Release/p:WebProjectOutputDir=D:\QuickQueryTest_Publish

 

WebProjectOutputDir 即Web发布的硬盘路径,按需设定。

 

所以设置完后进行保存.

 

2.2缺少的dll可以手动用xcopy来完成,当然也可以用附录的内部引用和外部引用完成,也是用使用 来增加一项:

xcopy"%JENKINS_HOME%\jobs\%JOB_NAME%\workspace\Engine\bin\Debug\Engine.dll"  C:\CTMTest_Publish\bin  /h /Y

xcopy"%JENKINS_HOME%\jobs\%JOB_NAME%\workspace\Engine\bin\Debug\CtmActiviti.dll"  C:\CTMTest_Publish\bin  /h /Y

xcopy"%JENKINS_HOME%\jobs\%JOB_NAME%\workspace\Engine\bin\Debug\AutoMapper.dll"  C:\CTMTest_Publish\bin  /h /Y

xcopy"%JENKINS_HOME%\jobs\%JOB_NAME%\workspace\Engine\bin\Debug\Uility.dll"  C:\CTMTest_Publish\bin  /h /Y

xcopy"%JENKINS_HOME%\jobs\%JOB_NAME%\workspace\Engine\bin\Debug\LibDb.dll" C:\CTMTest_Publish\bin  /h /Y

 

 

 

2.3压缩IIS虚拟路径的过时程序,使用

net use * /del /y

net use \\10.4.2.60\ctm-web"sh.1103" /user:"wanglin36"

C:\"Program Files (x86)"\7-Zip\7za c:\archive-%JOB_NAME%-%BUILD_ID%.zip \\10.4.2.60\ctm-web\*.* -r

 

这边\\10.4.2.60\ctm-web是发布服务器的IP,这边需要共享资源删除后再增加映射,否则会提示多人同时使用。

 

2.4把测试环境或者生产环境的web.config再恢复到新生成的发布包里

xcopy \\10.4.2.60\ctm-web\web.config  c:\CTMTest_Publish\web.config  /h /Y

3.      发布设置

可以新建 window cmd 命令来发布文件,例如:

 

net use \\ip\share "user" /user:"pwd"

del /q/a/f/s \\ ip \ folder \*.*

rd /s/q  \\ip\ folder \

xcopyE:\MyZone\Develop\WebPublish\CtmWeb\*.* \\ ip\folder /e /h

7.     构建 Job

打开http://localhost:8080

 

 

可以看到刚才新建并配置好的job,此时点击 可以进行构建操作。右侧的状态可以显示进度,点击进去可以查看详细的操作步骤.

 

 

5.     结束

好了,关于Jenkins QuickStart 结束了,这只是短时间内完成的一个简单的例子,如有不对欢迎指教。

 

 

附录F&Q

1.      如果服务器已经占用端口,如何改变端口?

打开jenkins安装目录下的Jenkins.xml文件,将其中的httpPort改为8081

2.      如何增加git拉取仓库的时间?

增加 -Dorg.jenkinsci.plugins.gitclient.Git.timeOut=60标签,这个60就是60分钟拉取时间。

3.      长时间git拉取仓库拉不到如何解决?

http://wanglin36:sh.1103@10.4.19.205/newctm_group/newctm2015.git/

这样就不用增加credentials的用户名凭证,尝试下来这样的拉取速度比较快,如果还是不行那就要考虑看看git和gitclient插件的版本是否有问题,最好是"Git plugin" to version 2.4.4 and"Git client plugin" to version 1.19.6

4.    安装服务器的时候需要安装什么软件?

 

按照上面的清单,安装BuildTools_Full是必须的,这样产生MSBUILD.exe,后面NDP46-KB3045557-x86-x64-AllOS-ENU是net framework 4.6的安装包,以NDP46-TargetingPack-KB3045566这个开头的也必须安装,包括中文本地化的安装包,Windows SDK需要根据 framework的版本酌情安装。

 

5.      如果有反射和注入等间接引用,Msbuild.exe web.csproj将不能引用带有反射和注入的DLL如何解决?http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx

有两种办法可以解决:

1)  简单

简单的最方便:

把这一段拷贝到web.csproj,其中..\Engine\bin\Debug\Engine.dll是编译后存放的地方,应该根据/t:ResolveReferences;Compile/t:_WPPCopyWebApplication /p:Configuration=Debug/p:WebProjectOutputDir=C:\CTMTest_Publish 配置中/p:Configuration=Debug来修改,简单的说,就是如果是Debug,这边的存放地址应该是..\Engine\bin\Debug\Engine.dll/p:Configuration=Release的话就是..\Engine\bin\Release\Engine.dll

<ReferenceInclude="Engine, Version=1.0.0.0, Culture=neutral,processorArchitecture=MSIL">

   <SpecificVersion>False</SpecificVersion>

    <HintPath>..\Engine\bin\Debug\Engine.dll</HintPath>

  </Reference>

  

  <Reference Include="CtmActiviti,Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">

   <SpecificVersion>False</SpecificVersion>

   <HintPath>..\Engine\bin\Debug\CtmActiviti.dll</HintPath>

  </Reference>

  <Reference Include="Uility.dll,Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">

   <SpecificVersion>False</SpecificVersion>

   <HintPath>..\Engine\bin\Debug\Uility.dll</HintPath>

  </Reference>

 <Reference Include="AutoMapper.dll,Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">

    <SpecificVersion>False</SpecificVersion>

   <HintPath>..\Engine\bin\Debug\AutoMapper.dll</HintPath>

  </Reference>

2)  复杂的

<ItemGroup>

  <BRSearchPathFiles Include="$(SolutionDir).\Engine\bin\Debug\*.dll"/>

</ItemGroup>

 <TargetName="BeforeResolveReferences">

  <RemoveDuplicatesInputs="@(BRSearchPathFiles->'%(RootDir)%(Directory)')">  

    <OutputTaskParameter="Filtered" ItemName="BRSearchPath" />

  </RemoveDuplicates>

 

 <CreatePropertyValue="@(BRSearchPath);$(AssemblySearchPaths)">

    <Output TaskParameter="Value"

      PropertyName="AssemblySearchPaths" />

        </CreateProperty>

</Target>

 

  当中的.\Engine\bin\Debug\*.dll也是根据Jenkins的MSBUILD配置来更改其中的Debug路径或者是Release路径。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值