title: Jenkins Declarative Pipeline - user variables in params
body: <p>I have a Jenkinsfle. I need to pass parameters from <em>Build with Parameters</em> plugin and also have variables defined within the script. I cannot get either to work. It may be a syntax issue?</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  pipeline {
    agent any
  
    stages {
     stage('Config API (dev)') {
        steps {
          script {
              apiName = "config_API"
              taskDefinitionFamily = "mis-core-dev-config"
              taskDefinition = "mis-core-dev-config"
              if (params.apiName.contains('Stop Task')) {
              build(job: 'Stop ECS Task (utility)',
              parameters: [
              string(name: 'region', value: params.region),
              string(name: 'cluster', value: params.cluster),
              string(name: 'family', value: params.taskDefinitionFamily)
              ])
            }
              else if (params."${apiName}".contains('Start Task')) {
              build(job: 'Start ECS Task (utility)',
              parameters: [
              string(name: 'region', value: params."${region}"),
              string(name: 'cluster', value: params."${cluster}"),
              string(name: 'taskDefinition', value: params."${taskDefinition}"),
              string(name: 'containerInstanceIds', value: params."${containerInstanceIdsToStartOn}")
              ])
            }
              else if (params."${apiName}" == null || params."${apiName}" == "") {
              echo "Did you forget to check a box?"
            }
          }
        }
      }
  </code></pre>
  
  <p>My <code>Build with parameters</code> variables are set in the GUI as `string variables,</p>
  
  <pre><code>containerInstanceIdsToStartOn = "463b8b6f-9388-4fbd-8257-b056e28c0a43"
  region = "eu-west-1"
  cluster = "mis-core-dev"
  </code></pre>
  
  <p>Where am I going wrong?</p>