How do I access parameters in a Jenkins pipeline script?

In addition to Bjorn Reppens example for declarative pipeline here is also one for scripted pipeline syntax:

properties([
  parameters([
    string( name: 'BuildConfiguration', 
            defaultValue: 'Release', 
            description: 'Configuration to build (Debug/Release/...)')
  ])
])

node{
 ...
}

Note that properties block can be specified inside node element or outside of it. Then you access your parameters just like in declarative pipeline via params.BuildConfiguration


First define your custom build parameter:

pipeline {
  parameters {
    string( name: 'BuildConfiguration', 
            defaultValue: 'Release', 
            description: 'Configuration to build (Debug/Release/...)')
  }

It will automatically show up in page shown after you click "Build with parameters" from the Jenkins job page.

Then access the variable inside the script:

echo "Building configuration: ${params.BuildConfiguration}"
echo "Building configuration: " + params.BuildConfiguration

If your parameter name has special characters in it such as dot or hyphen, you can access it this way:

pipeline {
    stages {
        stage('Test') {
            steps {
                echo "${params['app.jms.jndi-provider-url']}"
            }
        }
    }
}