title: jenkins declarative pipeline set variables derived from parameters
body: <p>I am using a declarative pipeline in a Jenkinsfile but I would like to derive some variables from a parameter.
  For example given:</p>
  
  <pre><code>parameters {
     choice(name: 'Platform',choices: ['Debian9', 'CentOS7'], description: 'Target OS platform', )
  }
  </code></pre>
  
  <p>I would like to add a block like:</p>
  
  <pre><code>script {
    switch(param.Platform) {
       case "Centos7":
           def DockerFile = 'src/main/docker/Jenkins-Centos.Dockerfile'
           def PackageType = 'RPM'
           def PackageSuffix = '.rpm'
           break
       case "Debian9":
       default:
           def DockerFile = 'src/main/docker/Jenkins-Debian.Dockerfile'
           def PackageType = 'DEB'
           def PackageSuffix = '.deb'
           break
    }
  }
  </code></pre>
  
  <p>Such that I can use variables elsewhere in the pipeline. For example:</p>
  
  <pre><code>agent { 
     dockerfile {
         filename "$DockerFile"
     }
  }
  </code></pre>
  
  <p>etc..</p>
  
  <p>but script is illegal in the parameter, environment &amp; agent sections.
  It can only be used in steps.</p>
  
  <p>I need to use the parameter in the agent block and I want to avoid repeating myself where the variables are used in different steps.</p>
  
  <p>Is there a sane way to achieve this? My preferences in order are:</p>
  
  <ul>
  <li>a declarative pipeline</li>
  <li>a scripted pipeline (less good)</li>
  <li>via a plugin to the Jenkins UI (least good)</li>
  </ul>
  
  <p>A shared library might be appropriate here regardless of whether it is actually shared.</p>
  
  <p>The intention is to support a multi-configuration project by creating a parameterised build and invoking it for different parameter sets with a red/blue status light for each configuration.
  It could be that I have assumed an 'old fashioned' design. In which case an acceptable answer would explain the modern best practice for creating a multi-configuration multi-branch pipeline. Something like: <a href="https://support.cloudbees.com/hc/en-us/articles/115000088431-Create-a-Matrix-like-flow-with-Pipeline" rel="nofollow noreferrer">https://support.cloudbees.com/hc/en-us/articles/115000088431-Create-a-Matrix-like-flow-with-Pipeline</a> or <a href="https://stackoverflow.com/questions/46601999/jenkins-pipeline-multiconfiguration-project">Jenkins Pipeline Multiconfiguration Project</a></p>
  
  <p>See also <a href="https://stackoverflow.com/q/56046541/1569204">Multiconfiguration / matrix build pipeline in Jenkins</a> for less specific discussion of best practices.</p>