在Jenkins上已经创建了一个任务并且已经添加了代码的分支,并且已经写了编译全部程序的脚本文件。这个时候你想通过新建一个Jenkins任务做部分子模块的编译操作但是又不想重新获取代码的分支(Jenkins上每一个任务对应不同的目录,如果设置了代码分支,那么获取代码后就是在不同目录,也就是说会有多份代码)。
这边说的是windows环境,linux也类似
::设置构建时间
set h=%time:~0,2%
::如果小时是个位数那么前面会有空格
set h=%h: =0%
set buildtime= %date:~0,4%%date:~5,2%%date:~8,2%-%h%%time:~3,2%%time:~6,2%
::代码更新操作(假设之前创建的Jenkins任务目录是OnlineServer)
set projpath=%JENKINS_HOME%/workspace/OnlineServer
cd %projpath%
git remote
git submodule init
git submodule sync
git config --get remote.origin.url
git submodule init
::git config -f .gitmodules --get-regexp ^submodule
::这边sdk为项目的字模块,如果后面有其他的项目子模块子要复制::sdk一下的脚本内容,然后把sdk替换成子模块的名称(名称在.gitsubmodule对应path的值)
::sdk
git config --get submodule.sdk.url
git remote
git config --get remote.origin.url
git config -f .gitmodules --get submodule.sdk.path
git submodule update --init --recursive --remote sdk
如果后续用VS进行编译的话调用 devenv "%projectpath%(sln文件路径)" /Rebuild "Release|Win32"
如果后续需要打包操作调用 rar a -df %buildtime%.rar *.dll *.exe(把目录下所有的dll和exe文件打包并且完成后删除dll和exe文件)