1

我想在 Hudson 中设置一个参数化构建,它只需要一个参数——要创建的构建类型(QA、Stage、Production)。但是,这些构建中的每一个都需要设置几个不同的环境变量。类似(伪代码):

if ${CONFIG} == "QA" then
    ${SVN_PATH} = "branches/dev"
    ${BUILD_CONFIG} = "Debug"
    # more environment variables...
else if ${CONFIG} == "Production" then
    ${SVN_PATH} = "trunk"
    ${BUILD_CONFIG} = "Release"
    # more environment variables...
else # more build configurations...
end if

在我们的构建中有无数的步骤——从 subversion 中提取,然后运行 ​​MSBuild 命令、DOS 批处理文件和 Powershell 脚本的组合。

我们通常从 Hudson 界面安排我们的构建,我希望参数条目尽可能地防白痴。

有没有办法做到这一点?

4

2 回答 2

6

Since you do so many things for a release, how about scripting all the steps outside of Hudson. you can use ant, batch files, or whatever scripting language you prefer. Put that script in your scm to get the revision control.

pro's:

  • you get the logic out of Hudson, since Hudson only calls the script.
  • You don't need to create environment variables that need to get persisted between shells (global variables).
  • you can use config/properties files for every environment, which you should also put into version control
  • you can run these scripts outside of Hudson, if you need to
  • Hudson job config get's way easier
  • you don't have the side effects of changing the global environment variables. You should always try to create jobs that don't change any global settings, because that always calls for trouble.
于 2010-12-03T12:36:37.373 回答
2

Hudson 支持构建参数,它们是构建时变量,Hudson 将其作为环境变量提供给您的构建步骤(请参阅 Hudson Parameterized Build wiki 页面)。在您的工作中,您可以选择CONFIG用户输入的一个参数。(要设置参数,请在您的作业配置下,选择This build is parameterized。)

然后,您基本上可以在构建步骤开始时用伪代码编写您编写的代码。或者,由于您有多个步骤,请将环境设置放在从现有构建脚本引用的文件中。(取决于您的 shell,有多种技巧可以将脚本中设置的变量导出到父环境。)将设置放入与现有构建脚本集成的文件中将使管理和测试变得更加容易(即它可以在外部测试Hudson) 以及为您提供一种在本地调用脚本的简单方法。

您还可以考虑将统一构建分成单独的作业,这些作业执行您描述的每个配置。尽管它们可能引用了一个中央构建脚本,但CONFIG您定义的类型似乎应该是不同的操作,并且应该有单独的工作。

于 2010-12-03T01:49:30.630 回答