jenkins windows slave 构建c/c++代码

        关于如何再centos系统上的jenkins master下搭建windows系统的jenkins slave节点,本篇博客中不做介绍,如果有需要的话,请参考我的另外一篇博客,在其中介绍了不同系统的jenkins slave的搭建,包含ios的,centos的,windows的,都是以我自己的实际搭建写的,并且有某些特殊情况的说明以及处理,非常适合做Jenkins的分布式构建的搭建链接是https://www.cnblogs.com/zndxall/p/8297356.html。

  本篇主要介绍如何在jenkins master上设置jenkins slave 构建c/c++的包。

1.在‘系统管理’--> "Global Tool Configuration"设置msbuild 配置,如下:

其中Name可以随意写,后面在任务设置中会使用到,最后设置和版本相关的,路径为你的jenkins slave上的msbuild.exe所在的目录,我的填写:

Name: MSBuild 14.0

Path to MSBuild:C:\Program Files (x86)\MSBuild\14.0\Bin

这时你可以会问,你的jenkins master是centos的系统啊,这个路径明显就是windows的路径啊,你不是应该去jenkins 的节点管理那里设置windows 节点吗?这个时候,上面截图中的黄色的提示语就很好的告诉了我们:

C:\Program Files (x86)\MSBuild\14.0\Bin is not a directory on the Jenkins master (but perhaps it exists on some agents)

他告诉我们这个地址master上不存在,可能在某个slave 节点上。所以,相信我,这样配置msbuild是没问题的。

一种方法是:用插件构建

  在任务设置的时候,设置构建在节点上进行,节点的设置如下:

在添加构建步骤时选择msbuild,如下:

设置如下:

 其中:

MSBuild Version: 就是上一步骤中设置的MSbuild的Name。

MSBuild File:是要构建的工程的sln的文件的路径。

Command Line Arguments: 是要执行的命令,/t:Rebuild /p:Configuration=Release;Platform=x86,其中Configuration 接的是构建类型,可是是Debug,也可以是Release;而Platfom指的是对应的平台,可以是x86,也可以是x64(但是遇到了一个问题,把x86换成Win32,一直报命令错误,不清楚怎么回事,大家可以试试,如果有明白的,可以在评论里给大家解释下)

 其他的设置,比如代码下载之类的,就不细说了,和jenkins master上配置是一样的。接下来就可以构建啦~~~

另一种方法:脚本实现

  此外,一般情况,除了单纯的构建,我们还需要指定分支,并切换到对应分支,构建结束后回收对应的文件到ftp上,这时你就可以用脚本实现了,脚本win_build.bat中的代码如下,供参考:

@echo off
echo vs_home=%VS2015_HOME%
set devenv="%VS2015_HOME%\Common7\IDE\devenv.com"
set msbuild="C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"
set vcvars="%VS2015_HOME%\VC/vcvarsall.bat"
set ftp_dir=\\192.168.8.2\ftp\output\Test
set cur_path=%cd%
set datevar=%date:~0,4%%date:~5,2%%date:~8,2%
set mytime=%time:~0,2%%time:~3,2%
set result_dir=%datevar%%mytime%
:: build type, debug or release
set type=%1
::build platform, x86 or x64
set platform=%2
::project sln name
set proj=%3
::build branch
set b_branch=%4
set sln_file=%cur_path%\build\win32\lesdk.sln
echo "++++++++++++input config:type=%type%,platform=%platform%,proj=%proj%,b_branch=%b_branch%+++++"
git checkout %b_branch%
git pull
echo "check branch:"
git branch
echo "=====================set %platform% env========================"
if "%platform%"=="x86" call %vcvars% x86
if "%platform%"=="x64" call %vcvars% x86_amd64

echo "==============starting build %platform% %type%================="
%msbuild% %sln_file% /t:Rebuild /p:Configuration=%type%;Platform=%platform%
::devenv 的 /projectconfig 必须和/project 参数一起使用
::%devenv% /Rebuild %type% %proj%.sln /project "%proj%/%proj%.vcxproj" /projectconfig "%type%|%platform%"

echo "===================copy result to ftp =========================="
echo result_dir=%result_dir%_%b_branch%_%platform%_%type%_lesdk
md target\%result_dir%_%b_branch%_%platform%_%type%_lesdk
move bin\win32\%type%\*.dll target\%result_dir%_%b_branch%_%platform%_%type%_lesdk\
move framecore\poco\bin\*.dll target\%result_dir%_%b_branch%_%platform%_%type%_lesdk\
xcopy /S /E /Y %cur_path%\target %ftp_dir%\
echo ftp_path=%ftp_dir%\%result_dir%_%b_branch%_%platform%_%type%_lesdk

然后在jenkins上设置bat脚本构建,构建命令为:call call win_build.bat Debug  x86   master

(这个插一句,以我的实际操作证明在jenkins  节点管理处设置msbuild 是没用的:

 我也去jenkins 节点管理出查找看能否设置,尽管我设置了msbuild.exe的路径,如下:

 这样你会发现在使用第一种方式构建(即插件构建)时,没有MSBuild Version可以选择)

猜你喜欢

转载自www.cnblogs.com/zndxall/p/9177866.html