简体   繁体   English

在Jenkins“ Execute Shell”中运行“ exec”命令

[英]Running the “exec” command in Jenkins “Execute Shell”

I'm running Jenkins on a Linux host. 我在Linux主机上运行Jenkins。 I'm automating the build of a C++ application. 我正在自动执行C ++应用程序的构建。 In order to build the application I need to use the 4.7 version of g++ which includes support for c++11. 为了构建该应用程序,我需要使用4.7版本的g ++,其中包括对c ++ 11的支持。 In order to use this version of g++ I run the following command at a command prompt: 为了使用此版本的g ++,我在命令提示符处运行以下命令:

exec /usr/bin/scl enable devtoolset-1.1 bash

So I created a "Execute shell" build step and put the following commands, which properly builds the C++ application on the command prompt: 因此,我创建了一个“执行外壳”构建步骤,并放置了以下命令,该命令可以在命令提示符下正确构建C ++应用程序:

exec /usr/bin/scl enable devtoolset-1.1 bash
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project

The problem is that Jenkins will not run any of the commands after the "exec /usr/bin/scl enable devtoolset-1.1 bash" command, but instead just runs the "exec" command, terminates and marks the build as successful. 问题在于,詹金斯将不会在“ exec / usr / bin / scl enable devtoolset-1.1 bash”命令之后运行任何命令,而是仅运行“ exec”命令,终止并标记构建成功。

Any ideas on how I can re-structure the above so that Jenkins will run all the commands? 关于如何重新构造上述内容以便让詹金斯运行所有命令的任何想法?

Thanks! 谢谢!

At the begining of your "Execute shell" script, execute source /opt/rh/devtoolset-1.1/enable to enable the devtoolet "inside" of your shell. 在“执行外壳”脚本的开始处,执行source /opt/rh/devtoolset-1.1/enable以在外壳内部启用devtoolet。

Which gives: 这使:

source /opt/rh/devtoolset-1.1/enable
libtoolize
autoreconf --force --install
./configure --prefix=/home/tomcat/.jenkins/workspace/project
make
make install
cd procs
./makem.sh /home/tomcat/.jenkins/workspace/project

I needed to look up what scl actually does. 我需要查看scl的实际功能。

Examples

scl enable example 'less --version'
    runs command 'less --version' in the environment with collection 'example' enabled
scl enable foo bar bash
    runs bash instance with foo and bar Software Collections enabled

So what you are doing is running a bash shell. 因此,您正在执行的是运行bash shell。 I guess, that the bash shell returns immediately, since you are in non-interactive mode. 我猜想,由于您处于非交互模式,因此bash shell立即返回。 exec runs the the command within the shell without creating a new shell. exec在外壳程序内运行命令而不创建新的外壳程序。 That means if the newly opened bash ends it also ends your shell prematurely. 这意味着如果新打开的bash结束,它也会过早地结束您的shell。 I would suggest to put all your build steps into a bash script (eg run_my_build.sh) and call it in the following way. 我建议将所有构建步骤放入bash脚本(例如run_my_build.sh)中,并通过以下方式进行调用。

exec /usr/bin/scl enable devtoolset-1.1 run_my_build.sh

This kind of thing normally works in "find" commands, but may work here. 这种事情通常在“查找”命令中起作用,但在这里可能起作用。 Rather than running two, or three processes, you run one "sh" that executes multiple things, like this: 而不是运行两个或三个进程,而是运行一个执行多个任务的“ sh”,如下所示:

exec sh -c "thing1; thing2; thing3" exec sh -c“事物1;事物2;事物3”

If you require each step to succeed before the next step, replace the semi-colons with double ampersands: 如果您要求每个步骤在下一步之前都成功,请用双“&”号代替分号:

exec sh -c "thing1 && thing2 && thing3" exec sh -c“事物1 &&事物2 &&事物3”

I have no idea which of your steps you wish to run together, so I am hoping you can adapt the concept to fit your needs. 我不知道您希望一起执行哪个步骤,因此我希望您可以修改该概念以适合您的需求。

Or you can put the whole lot into a script and exec that. 或者,您可以将全部内容放入脚本中并执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM