开发者

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

开发者 https://www.devze.com 2023-04-10 22: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 repos

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 environmenta开发者_如何学Gol 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


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.


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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消