Skip to main content

Working with Build Parameters

1. Adding String Parameters

Property Value Description
name string Name of the parameter
default string Default value for the parameter
description string Description shown to users

Example: Adding String Parameter

parameters {
    stringParam("BUILD_NUMBER", "1.0.0", "Build version to use")
}

2. Adding Choice Parameters

Property Value Description
name string Name of the parameter
choices list of strings List of available options
default string Default selected option

Example: Adding Choice Parameter

parameters {
    choiceParam("ENVIRONMENT", ["dev", "staging", "prod"], "dev")
}

3. Adding Boolean Parameters

Property Value Description
name string Name of the parameter
default boolean Default value (true/false)
description string Description shown to users

Example: Adding Boolean Parameter

parameters {
    booleanParam("DEBUG_MODE", false, "Enable debug mode")
}

4. Adding File Parameters

Property Value Description
name string Name of the parameter
default string Default file path
description string Description shown to users

Example: Adding File Parameter

parameters {
    fileParam("CONFIG_FILE", "/etc/config.json", "Configuration file path")
}

5. Adding Password Parameters

Property Value Description
name string Name of the parameter
default string Default password value (optional)
description string Description shown to users

Example: Adding Password Parameter

parameters {
    passwordParam("DB_PASSWORD", "", "Database password")
}

6. Using Multi-Line String Parameters

Property Value Description
name string Name of the parameter
default string Default multi-line value
description string Description shown to users

Example: Using Multi-Line String Parameter

parameters {
    stringParam("SCRIPT", """
echo 'Hello World'
echo 'Build completed'
""", "Script to run")
}

7. Using Extended Choice Parameters

Property Value Description
name string Name of the parameter
choices list of strings List of available options
description string Description shown to users

Example: Using Extended Choice Parameter

parameters {
    extendedChoiceParam("ENVIRONMENT", ["dev", "staging", "prod"], "dev")
}

8. Accessing Parameters in Builds

Property Value Description
Access Method env.PARAM_NAME Environment variable access
Access Method params.PARAM_NAME Build parameter access
Type string Parameter type

Example: Accessing Parameters in Build Script

pipeline {
    agent any
    parameters {
        stringParam("BUILD_NUMBER", "1.0.0", "Build version to use")
    }
    stages {
        stage("Build") {
            steps {
                echo "Building version ${env.BUILD_NUMBER}"
                sh "echo 'Build number is $BUILD_NUMBER'"
            }
        }
    }
}

9. Using Dynamic Parameters

Property Value Description
name string Name of the parameter
value closure Closure that returns parameter value
description string Description shown to users

Example: Using Dynamic Parameter

parameters {
    dynamicParam("TIMESTAMP", { new Date().format("yyyyMMdd-HHmmss") }, "Current timestamp")
}

10. Validating Parameter Values

Property Value Description
Validation Rule regex Regular expression to validate input
Validation Rule min/max length Length constraints on input
Validation Rule custom validation Custom logic to validate input

Example: Validating Parameter Values

parameters {
    stringParam("BUILD_NUMBER", "", "Build version to use")
    validation {
        regex("BUILD_NUMBER", "^\\d+\\.\\d+\\.\\d+$", "Must be in semver format")
    }
}

Was this article helpful?