简体   繁体   English

Groovy在Jenkins中执行Bash脚本

[英]Groovy Execute Bash Script in Jenkins

I am trying to run a bash script from Groovy in Jenkins but I am not able to find the lucky commands. 我正在尝试在詹金斯的Groovy中运行bash脚本,但找不到幸运的命令。

I can run this and it creates my "RJ" directory: 我可以运行它,它会创建我的“ RJ”目录:

process = "mkdir /app/jenkins/workspace/TEST/RJ"
println process.execute()

But when I try to run my bash it is not creating my output file. 但是,当我尝试运行bash时,它并没有创建我的输出文件。 I am able to run this bash script on the server directly and it is creating my expected output file. 我能够直接在服务器上运行此bash脚本,并且它正在创建预期的输出文件。

process = "/app/jenkins/workspace/TEST/info_file.sh"
println process.execute()

why run it through groovy and not directly via a ssh command. 为什么通过groovy而不是直接通过ssh命令运行它。

If you do want to do via groovy, you'll need to add a ssh libray, and do the whole connection, auth, execute. 如果您确实想通过groovy进行操作,则需要添加ssh libray,并进行整个连接,身份验证和执行。 process.execute won't run a linux box. process.execute将不会运行linux系统。

first, you don't check the stderr and not waiting for process to end. 首先,您无需检查stderr,也不必等待进程结束。

similar problem was here: 类似的问题在这里:

Curl request from command line and via Groovy script 通过命令行和Groovy脚本卷曲请求

with error text it's easier to solve the error. 使用错误文本,更容易解决错误。

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

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