Jenkins 键值变量或使用一个变量定义另一个变量

发布于 2024-12-07 22:59:33 字数 359 浏览 4 评论 0原文

我正在建立一个集中式构建系统,其中几个项目被“打包”。可以使用选择参数来选择项目,并基于它我正在构建 SVN 签出路径。存储库是相同的,但每个应用程序的路径略有不同,例如:

  • 应用程序 1 驻留在 ../libs/App1..
  • 应用程序 2 驻留在 ../tools/App2..

我的问题是我需要以某种方式将应用程序名称与其位置相匹配。

我首先想到的是键值参数,但我还没有找到允许它的插件。

第二个是在文件中定义一些环境变量(有 2-3 个插件可以做到这一点),然后使用在 choice 参数中选择的值作为环境变量的键。这可以通过任何方式实现吗?

亲切的问候

I'm setting up a centralized build system where several projects get "packaged". The project can be selected using a choice parameter, and based on it I'm building the SVN checkout path. The repository is the same, but each app has a slightly different path, eg:

  • app 1 resides in ../libs/App1..
  • app 2 resides in ../tools/App2..
  • etc

My problem is that I need to somehow match the app name with its location.

The first thought that came to mind was a key-value parameter but I have yet to find a plugin that permits it.

The second one was to define some environmental variables within a file (there are 2-3 plugins that do it) and then use the value selected in the choice parameter to as the key for the env var. Is this achievable in any way?

Kind regards

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

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

发布评论

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

评论(2

怕倦 2024-12-14 22:59:33

您可以将 条件 BuildStep 插件EnvInject 插件 以设置环境变量(例如 APP_PATH)取决于任何其他构建步骤之前的构建参数。然后,当您在构建中需要时,您可以使用 ${APP_PATH}

You can use Conditional BuildStep Plugin together with EnvInject Plugin in order to set up an environment variable (say APP_PATH) that depends on your build parameters before any other build steps. You then use ${APP_PATH} whenever you need it in your build.

前事休说 2024-12-14 22:59:33

几年后:-)在一个不相关的主题上,我发现了 主动选择插件也称为/派生自uno choice插件允许定义在更改其他参数时动态更新的参数:

1)定义一个名为states主动选择参数以下 groovy-script 内容

return[
'Sao Paulo',
'Rio de Janeiro',
'Parana',
'Acre'
]

2) 定义一个名为 cities主动选择反应参数,它对第一个参数值的变化做出反应,使用以下 groovy -脚本内容:

if (States.equals("Sao Paulo")) {
  return ["Barretos", "Sao Paulo", "Itu"]
} else if (States.equals("Rio de Janeiro")) {
  return ["Rio de Janeiro", "Mangaratiba"]
} else if (States.equals("Parana")) {
  return ["Curitiba", "Ponta Grossa"]
} else if (States.equals("Acre")) {
  return ["Rio Branco", "Acrelandia"]
} else {
  return ["Unknown state"]
}

因此,每次发生变化,则可选择的城市列表将相应更新:

在此处输入图像描述

After a few years :-) and on an unrelated topic, I found the Active choices plugin also known as / forked from uno choice plugin which allows to define parameters which dynamically update when changing other parameters:

1) define an active choice parameter named states with the following groovy-script content

return[
'Sao Paulo',
'Rio de Janeiro',
'Parana',
'Acre'
]

2) Define an active choice reactive parameter named cities which reacts to changes in the first parameter's value, with the following groovy-script content:

if (States.equals("Sao Paulo")) {
  return ["Barretos", "Sao Paulo", "Itu"]
} else if (States.equals("Rio de Janeiro")) {
  return ["Rio de Janeiro", "Mangaratiba"]
} else if (States.equals("Parana")) {
  return ["Curitiba", "Ponta Grossa"]
} else if (States.equals("Acre")) {
  return ["Rio Branco", "Acrelandia"]
} else {
  return ["Unknown state"]
}

Thus, each time the state changes, then the list of selectable cities will be updated accordingly:

enter image description here

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