如何在Jenkinsfile中执行Shell脚本? [英] How can I execute Shell script in Jenkinsfile?

查看:2540
本文介绍了如何在Jenkinsfile中执行Shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在/var/lib/jenkins中保留一个名为urltest.sh的shell脚本文件,并从jenkins构建中执行该文件.

I am keeping a shell script file named urltest.sh in /var/lib/jenkins and executing the file from jenkins build.

执行构建时,它失败.

When I execute the build, It fails.

The Environment Variables are - 
HOME -          /var/lib/jenkins ;
JENKINS_HOME -  /var/lib/jenkins

控制台输出为:

Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/AutoScript
[AutoScript] $ /bin/sh -xe /tmp/hudson2777728063740604479.sh
+ sh urltest.sh
sh: 0: Can't open urltest.sh
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我很困惑应该在何处保存shell脚本文件以便执行该文件.

I am confused where I should keep the shell script file so that it is executed.

推荐答案

如果看到错误消息,则显示为

If you see your error message it says

在工作区/var/lib/jenkins/workspace/AutoScript中构建

Building in workspace /var/lib/jenkins/workspace/AutoScript

,根据您的评论,您将urltest.sh放入

and as per your comments you have put urltest.sh in

/var/lib/jenkins

/var/lib/jenkins

因此Jenkins无法找到该文件. 在您的构建步骤中执行此操作,它将成功

Hence Jenkins is not able to find the file. In your build step do this thing, it will work

cd             # which will point to /var/lib/jenkins
./urltest.sh   # it will run your script

如果仍然失败,请尝试将文件扔掉,因为jenkin用户可能没有文件许可权,但是我认为,如果您执行上述步骤,您将可以运行.

If it still fails try to chown the file as jenkin user may not have file permission, but I think if you do above step you will be able to run.

这篇关于如何在Jenkinsfile中执行Shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆