bash Jenkins - 执行 Shell 构建步骤不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27412349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:59:28  来源:igfitidea点击:

Jenkins - Execute Shell Build Step Not Working

bashshelljenkins

提问by Chiefwarpaint

I'm trying to create a job in Jenkins that will execute a simple shell script. However, it seems that Jenkins isn't actually doing anything with my script. No matter what value I put into the Execute Shell Commandsection, Jenkins always says that it passes. Even if I put in a bogus filename like "RandomBogusFilename.sh" it'll say the job was a success.

我正在尝试在 Jenkins 中创建一个将执行一个简单的 shell 脚本的工作。然而,詹金斯似乎并没有真正对我的脚本做任何事情。无论我在Execute Shell Command部分输入什么值,Jenkins 总是说它通过了。即使我输入了一个像“RandomBogusFilename.sh”这样的虚假文件名,它也会说这项工作是成功的。

Can anyone point out what I'm doing wrong and how I can get Jenkins to actually use my shell script?

谁能指出我做错了什么以及如何让 Jenkins 实际使用我的 shell 脚本?

The shell script, the job config, and the console output are all shown below. I'm currently trying to do this on a Windows Server 2008 R2 Standardmachine.

shell 脚本、作业配置和控制台输出都如下所示。我目前正在尝试在Windows Server 2008 R2 Standard机器上执行此操作。

Thanks.

谢谢。



My .sh file

我的 .sh 文件

File Name:surveyToolRequest.sh
File Location:/jobs/Jeff Shell Script Test/workspace
Description:Hit a web address and retrieve the HTTP Response. Then print out the HTTP Response.

文件名:surveyToolRequest.sh
文件位置:/jobs/Jeff Shell Script Test/workspace
描述:点击网址并检索 HTTP 响应。然后打印出 HTTP 响应。



#!/bin/bash

response_code=$(curl -s -o /dev/null -w "%{http_code}" http://SOME-WEBSITE.COM)
echo "The response code is " $response_code  






My Jenkins Job Config

我的 Jenkins 作业配置



Jenkins Job Config

詹金斯作业配置







Jenkins Console Output

詹金斯控制台输出



enter image description here

在此处输入图片说明



回答by gareth_bowles

I played with this and found that it worked if I specified the path to the script. If the script is in your job's workspace directory,

我玩了这个,发现如果我指定了脚本的路径,它就可以工作。如果脚本在您作业的工作区目录中,

./surveyToolRequest.sh

should work as Jenkins looks for files relative to the root of the workspace.

应该在 Jenkins 查找与工作区根目录相关的文件时工作。

It's more common to just put the contents of the script file directory into the job configuration; that way you can see what the job is doing and you'll avoid problems like this one.

更常见的做法是将脚本文件目录的内容放入作业配置中;这样你就可以看到工作在做什么,你就会避免这样的问题。

回答by kazerm

You should use run "Execute windows batch command" and not "Execute Shell"

您应该使用运行“执行 Windows 批处理命令”而不是“执行外壳”