Jenkins Dynamic Parameter

I want deploy an infrastructure in amazon , it must be multi region, I have a list of available networks depending from the region.
I want have a jenkins job that update the network select box depending from the chosen region

Plugin used

You need to have installed the plugin Uno Choice Parameter and use this option
To install this plugin you can find in the page jenkins-summary you need to do some steps.

My working example

it is not easy find the right groovy code that works also in jenkins, I found other groovy code that was working from command line but they failed when you put inside the jenkins parameter
the aws_region can be a normal choice parameter, I used an extended choice parameter with a property file but it is irrelevant Here the image of the parameter configuration

networks code, this read files

import static

if (binding.variables.get('aws_region') != null) {
  region = binding.variables.get('aws_region')
  def dir = new File("/home/ec2-user/git-repos/jenkins-networks/"+region+"/available/"); 
  def files = [];
  dir.traverse(type: FILES, maxDepth: 0) { def values = (it.toString()).split('/');  def net =""+values[values.size()-1]+"/16" ; files.add(net) };

  return  files


Another Groovy script

this instead read directories, don't depend from another parameter

import static

def dir = new File("/home/ec2-user/git-repos/terraform-main-source-only/versions/"); 
def files = [];
dir.traverse(type: DIRECTORIES, maxDepth: 0) { def values = (it.toString()).split('/'); files.add(values[values.size()-1]) };
return files
Salvo diversa indicazione, il contenuto di questa pagina è sotto licenza Creative Commons Attribution-ShareAlike 3.0 License