我有一个要在Ubuntu 15.10上运行的Jenkins上构建的CMake示例项目。我已经安装了:
https://wiki.jenkins-ci.org/display/JENKINS/CMake+Plugin
并创建了两个构建步骤:
它工作正常:
[build] $ cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug /var/lib/jenkins/workspace/cmake-test/cmake-gtest/src
-- Configuring done
-- Generating done
-- Build files have been written to: /var/lib/jenkins/workspace/cmake-test/cmake-gtest/build
[build] $ /usr/bin/make
[ 4%] Built target libfoo
[ 9%] Built target libbar
[ 14%] Built target myApp
[ 52%] Built target gmock
[ 90%] Built target gtest
[100%] Built target testfoo
[cmake-test] $ /bin/sh -xe /tmp/hudson1792271459427590561.sh
+ cd cmake-gtest/build
+ make all
[ 4%] Built target libfoo
[ 9%] Built target libbar
[ 14%] Built target myApp
[ 52%] Built target gmock
[ 90%] Built target gtest
[100%] Built target testfoo
Finished: SUCCESS
但这是在CI / Jenkins设置中使用CMake的推荐方法吗?
目前,我的CMake / Jenkins构建将在每次推送时进行;1)生成makefile,2)生成项目。
I am a bit worried that the first step 1) generate makefiles would eat up build time and it does not really seem optimal to do this step on each push. Especially since I would not expect to change CMakeLists.txt files that often, but when they change newly generated files should, of course, be used.
Is the above approach common practices that I just have to get used to or have I missed something?
Yes, you can do it in one step.
For example, in my Jenkins environment, when building the Ubuntu jobs I use the CMake plugin for the whole compilation, as it allows multiple build tool invocations.
My screenshot at the bottom of this post is of a CMake step in a job (I use Ninja instead of Unix Makefiles, but the effect is the same).
I use two build invocations:
ninja
or make
in a shell,DESTDIR=. ninja install
.If I wanted to build additional targets from the makefiles, I could just add extra invocations to this step.
Note that in your screenshot you have a blank invocation in the configuration. This will already be calling make
, and as confirmed by your log output, you are in fact compiling your project twice, because of your manual call to make all
in the following step.
You can remove your shell step and your project will still build.
Regarding your question on best practices and regenerating CMake, I refer you to this article on Jenkins Best Practices where it states:
为确保生成可复制,该生成必须是完整的生成,其完全由源代码控制构建。这种做法还意味着必须将所有代码(包括第三方jar,构建脚本,发行说明等)检入Source Code Control。
请注意,我还在我的CMake步骤中选中了“清理构建”,以便清除整个CMake工作区,并为每个构建从头开始生成项目。这样可以确保不会出现由过时的缓存变量等引起的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句