简体   繁体   English

通过Jenkins中的shell通过execute命令运行python脚本

[英]Running python script via execute command from shell in Jenkins

The Jenkins job is set up so that it checks out latest version of a git repo which executes some python code. 设置Jenkins作业,以便它签出执行某些python代码的git repo的最新版本。 The git repo is checked out to our linux lab pc and it runs there. git repo已签出到我们的linux实验室PC,并在那里运行。

In the script, we are checking status of some labpc network interfaces. 在脚本中,我们正在检查某些labpc网络接口的状态。 I made a small script which executes the following lines but it throws error like "no file or directory." 我做了一个小的脚本,该脚本执行以下行,但是会引发诸如“无文件或目录”之类的错误。 The command is ok but it fails because linux env is not visible. 该命令还可以,但由于看不到linux env而失败。 The strange thing is that we have like 10 testcases and in 6 of them it works perfectly fine and it 4 it fails and it always fails for just those. 奇怪的是,我们有10个测试用例,其中6个用例非常好,而4个用例却失败了,而对于那些用例来说总是失败。 The sequence of events is exactly the same in all the testcases ... 在所有测试用例中,事件的顺序完全相同...

res = subprocess.check_output(['ip', 'link', 'show', 'dev', '<interface name>'])
logger.info(res)

The scripts works when executed locally so there is jenkins issue which is behind this. 该脚本在本地执行时有效,因此存在jenkins问题。 Does anybody have any tips to resolve this? 有人有解决此问题的提示吗?

The problem is solved by putting 'sudo' before the command. 通过在命令前放置“ sudo”可以解决该问题。 Even though the command doesn't require sudo rights, it requires it when run with jenkins. 即使该命令不需要sudo权限,但在与jenkins一起运行时也需要它。

You can open in jenkins the node where you can execute groovy commands to the server and test that it works. 您可以在jenkins中打开可以对服务器执行groovy命令并测试其正常工作的节点。

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

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