如何将hudson的环境变量作为svn构建的参数传递

发布于 2024-09-28 12:08:36 字数 430 浏览 1 评论 0原文

我的要求是我需要子项目的 svn url 构建参数中 Hudson 环境变量的范围。

我想将 SVN 分支名称设置为 Hudson 的环境变量,因为我希望在那里配置的所有项目都使用它。

如果我将环境变量 [BUILD_BRANCH] 访问为

http://svn/repos/project/subproj/branches/ ${BUILD_BRANCH}

url 没有被值替换。

但在同样的情况下,如果我在每个子项目中将 BUILD_BRANCH 作为参数化构建的字符串参数,则 url 将替换为值。但我不能在所有项目中每次都更改分支值[构建参数值]。此外,下游项目无法访问调用项目的构建参数 [String]。

My requirement is I need the scope of Hudson's environment variable in the subproject's build parameter for svn url.

I want to set SVN Branch name as an environment variable of Hudson, as I want it to be used by all my projects configured there.

If I access my environment variable [BUILD_BRANCH] as

http://svn/repos/project/subproj/branches/${BUILD_BRANCH}

the url is not getting replaced with the value.

But in the same case if I have BUILD_BRANCH as String Parameter for Parameterised Build in each subproj the url is replaced with value. But I cannot not change the branch value [build parameter value] each time in all the projects. Also the downstream projects were not able to access the build parameters [String] of the calling projects.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

楠木可依 2024-10-05 12:08:36

构建配置中有一个名为“此构建已参数化”的复选框。

如果启用该功能,您将能够为此特定构建创建参数。

我希望这会有所帮助。

There is a checkbox called: "This build is Parameterized" in the build's configuration.

If you enable that, you will be able to create parameters to this specific build.

I hope that this helps.

情话难免假 2024-10-05 12:08:36

让我澄清一下你的问题。您已经定义了一个环境变量 BUILD_BRANCH 并希望能够从构建的参数中引用它。是这样吗?

如果是这样的话,那么我已经解决了你的问题!

当评估参数时(并且扩展其中引用的任何变量),您无权访问环境变量,因此参数的值最终是文字字符串“${BUILD_BRANCH}”,而不是扩展为$BUILD_BRANCH 的环境定义。

然后,当您从 shell 脚本引用参数时,参数的值会用单引号引起来,从而防止解析额外的间接层,因此您获得的是环境变量的名称,而不是其值。

解决方案是将 eval 添加到引用参数的每行 shell 脚本的开头,这将解析额外的层,并且变量将起作用。

最后一件事 - 如果您引用先前的参数,则不必执行此操作。因此,如果 Param1 是 foo,Param2 是 ${foo} bar,则这将起作用,因为参数是按顺序计算的。但是,如果切换参数值,则需要使用 eval。

Let me clarify your problem. You have defined an environment variable, BUILD_BRANCH and want to be able to reference it from within a parameter for your build. Is that right?

If that's the case, then I have solved your problem!

When parameters are evaluated (and any variables referenced within them are expanded), you don't have access to environment variables, so the value of the parameter ends up being the literal string '${BUILD_BRANCH}', rather than being expanded to the environment definition of $BUILD_BRANCH.

Then when you reference the parameter from shell script, the value of the parameter is surrounded in single quotes, preventing the extra layer of indirection from being resolved, so you get the name of your environment variable, rather than its value.

The solution is to add eval to the start of each line of shell script where you reference the parameter, which will resolve the extra layer, and the variable will work.

One last thing- you don't have to do this if you are referencing a previous parameter. So if Param1 is foo, and Param2 is ${foo} bar, this will work, because the parameters are evaluated in order. If the parameter values were switched, however, you would need to use eval.

柠檬色的秋千 2024-10-05 12:08:36

目前似乎没有办法使用环境变量来调整 subversion 存储库位置。我决定做的是使用脚本在外部编辑 config.xml 文件。

如果该变量的值以编程方式更改,这可能对您不起作用,但对我们来说,我希望能够在分支和主干之间迁移我们的作业,这是每个冲刺完成的手动过程。

像下面这样的某种脚本对我们有用:

FROM_SVN_PATH="svnserver.com/trunk"
TO_SVN_PATH="svnserver.com/branches/1.1"
cd jobs
for f in */config.xml
do
    sed -e "s,$FROM_SVN_PATH,$TO_SVN_PATH," < "$f" > "$f.t"
    mv "$f" "$f.ORG"
    mv "$f.t" "$f"
done

如果您使用 Jenkins,则可以转到“管理 Jenkins”并选择“从磁盘重新加载配置”。

It seems like there is no current way to use a environmental variable to adjust the subversion repository location. What I decided to do is to edit the config.xml files outside with a script.

This may not work for you if the value of that variable is changing programmatically, but for us, I wanted to be able to migrate our jobs between branches and trunk which is done every sprint and is a manual process.

Some sort of script like the following works for us:

FROM_SVN_PATH="svnserver.com/trunk"
TO_SVN_PATH="svnserver.com/branches/1.1"
cd jobs
for f in */config.xml
do
    sed -e "s,$FROM_SVN_PATH,$TO_SVN_PATH," < "$f" > "$f.t"
    mv "$f" "$f.ORG"
    mv "$f.t" "$f"
done

If you are using Jenkins, you can then go to "Manage Jenkins" and select "Reload Configuration from Disk".

此生挚爱伱 2024-10-05 12:08:36

在 ManageHudson-> 配置系统-> 全局属性-> 环境变量中设置 BUILD_BRANCH

set BUILD_BRANCH in ManageHudson->Configure System->Global properties->Environment Variables

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文