bash 我可以使用 cygwin 编写 hudson 构建步骤的脚本吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/731705/
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-17 20:48:17  来源:igfitidea点击:

Can I use cygwin to script a hudson build step?

bashcontinuous-integrationcygwinhudson

提问by Jason Baker

I've tried executing the following:

我尝试执行以下操作:

#!C:\cygwin\bin\bash.exe
ls ${WORKSPACE}

But that doesn't find ls (even if it's on the windows path). Is there any way to set this up?

但这并没有找到 ls (即使它在 Windows 路径上)。有没有办法设置这个?

UPDATE: In other words, I want to be able to set up a build step that uses cygwin bash instead of windows cmd like this pageshows you how to do with Python.

更新:换句话说,我希望能够设置一个使用 cygwin bash 而不是 windows cmd 的构建步骤,就像这个页面向您展示如何使用 Python。

回答by lhunath

So put your cygwin's bindirectory in your PATH.

所以把你cygwinbin目录放在你的PATH.

In case you don't know how to do it (Control Panel-> System-> Advanced-> Environment Variables), see: http://support.microsoft.com/kb/310519

如果您不知道该怎么做(Control Panel-> System-> Advanced-> Environment Variables),请参阅:http://support.microsoft.com/kb/310519

回答by JesperE

That shell-script has two errors: the hash-bang line should be "#!/bin/bash", and ${WORKSPACE} is not a shell-variable. Hudson has a bunch of variables of its own which are expanded in the commands you specify to be run (i.e. when you add commands in the web gui).

该 shell 脚本有两个错误:hash-bang 行应该是“#!/bin/bash”,并且 ${WORKSPACE} 不是 shell 变量。Hudson 有一堆自己的变量,它们在您指定要运行的命令中扩展(即当您在 web gui 中添加命令时)。

If you want to run Hudson build step on the Cygwin command line, you need to figure out what command Hudson runs and in which directory.

如果要在 Cygwin 命令行上运行 Hudson 构建步骤,则需要弄清楚 Hudson 运行的命令以及在哪个目录中。

To give a more specific answer, you need to show us how your project is configured and what steps you want to run separately.

要给出更具体的答案,您需要向我们展示您的项目是如何配置的以及您希望单独运行哪些步骤。

回答by Soo Wei Tan

Provided cygwin's bin folder is in your path, the following works for me:

如果 cygwin 的 bin 文件夹在您的路径中,以下内容对我有用:

#!/bin/sh
ls ${WORKSPACE}

I find Hudson does not pick up environment variable changes unless you restart the server.

我发现除非您重新启动服务器,否则 Hudson 不会获取环境变量更改。

回答by webwesen

you might want to try to give a full path to ls

您可能想尝试提供 ls 的完整路径

/cygdrive/c/cygwin/bin/ls

回答by Jason Baker

One other thing that seems to work is to use this:

另一件似乎有效的事情是使用这个:

#!C:\cygwin\bin\bash.exe
export PATH=$PATH:/usr/bin
ls

But it would be nice not to have to modify the path for every script.

但是最好不必修改每个脚本的路径。

回答by Bob The Janitor

Have you thought about power shell? as much as I like cygwin, it's always been a little flaky, powershell is a solid fully functional shell on windows, another option is Windows Services for UNIXit gives you korn shell or c shell not quite as nice as bash but it gets the job done

你有没有想过电源外壳?尽管我喜欢 cygwin,但它总是有点不稳定,powershell 是Windows上一个可靠的全功能 shell,另一个选项是Windows Services for UNIX它为您提供 korn shell 或 c shell 不如 bash 好,但它得到了工作完毕

回答by Colin D Bennett

You will need to pass the --login(aka -l) option to bashso that it will source Cygwin's /etc/profileand set up the PATHvariable correctly. This will cause the current directory to get changed to the default "home" but you can set the environment variable CHERE_INVOKINGto 1before running bash -land it will stay in the current directory if you need to preserve that.

您需要将--login(又名-l)选项传递给 ,bash以便它可以获取 Cygwin 的源/etc/profilePATH正确设置变量。这将导致当前目录得到改变默认的“家”,但你可以在环境变量设置CHERE_INVOKING1运行之前bash -l,它会留在当前目录下,如果你需要保留这一点。