Jenkins key-value variable or using a variable to define another

半城伤御伤魂 提交于 2019-12-13 01:13:27

问题


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


回答1:


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.




回答2:


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:



来源:https://stackoverflow.com/questions/7636547/jenkins-key-value-variable-or-using-a-variable-to-define-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!