Smart Parameter is a Jenkins plugin that enables conditional parameters in your build forms. It dynamically shows or hides input fields based on the values of other parameters, creating cleaner, more intuitive build forms that adapt to user selections.
This plugin is perfect for complex build pipelines where parameter choices determine which additional options are relevant.
- Conditional Visibility: Show or hide parameters based on the values of other parameters
- Multiple Condition Types: Support for equals, not equals, contains, starts with, ends with, and regex pattern matching
- Multiple Condition Logic: Combine conditions with AND/OR operators for complex logic
- Parameter Wrappers: Control the visibility of existing parameter types
- Multiple Reference Parameters: Control multiple parameters with a single wrapper
- Simple Configuration: Easy to set up in your job's parameter definitions
- Real-time Updates: Parameters update immediately when controlling values change
- Go to Manage Jenkins > Manage Plugins > Available tab
- Search for "Smart Parameter"
- Check the box next to "Smart Parameter Plugin" and click "Install without restart"
The plugin provides four parameter types:
- Smart Parameter: Basic parameter with conditional visibility based on a single condition
- Smart Parameter (Multiple Conditions): Enhanced parameter with multiple conditions combined by AND/OR logic
- Smart Wrapper Parameter: Wraps existing parameters and controls their visibility based on a single condition
- Smart Wrapper Parameter (Multiple Conditions): Controls visibility of referenced parameters based on multiple conditions
This is the basic parameter type with a single visibility condition.
- In your Jenkins job configuration, go to the "This project is parameterized" section
- Click "Add Parameter" and select "Smart Parameter"
- Fill in the required fields:
- Name: A unique identifier for the parameter
- Default Value: The default value for the parameter
- Description: A helpful description of the parameter
- Configure the conditional visibility section:
- Control Parameter: The name of another parameter that controls visibility
- Condition: Select one of: equals, not equals, contains, starts with, ends with, matches regex
- Control Value: The value to compare against
This parameter type allows for more complex logic with multiple conditions combined by AND/OR operators.
- Click "Add Parameter" and select "Smart Parameter (Multiple Conditions)"
- Fill in the basic parameter information (Name, Default Value, Description)
- Configure the conditional visibility section:
- Logical Operator: Choose between AND (all conditions must be true) or OR (any condition can be true)
- Conditions: Click "Add Condition" to add multiple conditions
- For each condition, specify:
- Control Parameter: The name of the parameter that controls visibility
- Condition: Type of condition (equals, not equals, contains, etc.)
- Control Value: The value to compare against
This parameter type doesn't add a new input field but instead controls the visibility of other parameters.
- Click "Add Parameter" and select "Parameter Wrapper"
- Fill in:
- Name: A unique identifier (not shown to users)
- Description: Optional description (not shown to users)
- Configure:
- Control Parameter: The parameter that controls visibility
- Condition: Type of condition (equals, not equals, contains, etc.)
- Control Value: The value to compare against
- Referenced Parameters: Comma-separated list of parameter names to control
This is the most powerful parameter type, allowing you to control visibility of other parameters using multiple conditions.
- Click "Add Parameter" and select "Smart Wrapper Parameter (Multiple Conditions)"
- Fill in the basic information (Name, Description)
- Configure:
- Logical Operator: Choose between AND or OR logic
- Conditions: Add multiple conditions as needed
- Referenced Parameters: Comma-separated list of parameter names to control
Let's say you have a job with a "DEPLOYMENT_ENV" choice parameter with values "dev", "staging", and "prod". You might want to add additional parameters that are only relevant for specific environments:
-
Add a "Smart Parameter" named "STAGING_CONFIG" with:
- Control Parameter: DEPLOYMENT_ENV
- Condition: equals
- Control Value: staging
-
Add another "Smart Parameter" named "PRODUCTION_APPROVER" with:
- Control Parameter: DEPLOYMENT_ENV
- Condition: equals
- Control Value: prod
For a more complex scenario, let's say you want to show a database configuration parameter only when:
- The deployment environment is "prod" AND the region is "us-east"
- OR when the deployment type is "database-migration"
- Add a "Smart Parameter (Multiple Conditions)" named "DB_CONFIG" with:
- Logical Operator: OR
- First condition:
- Logical Operator: AND
- Sub-condition 1:
- Control Parameter: DEPLOYMENT_ENV
- Condition: equals
- Control Value: prod
- Sub-condition 2:
- Control Parameter: REGION
- Condition: equals
- Control Value: us-east
- Second condition:
- Control Parameter: DEPLOYMENT_TYPE
- Condition: equals
- Control Value: database-migration
To control multiple existing parameters with a single condition:
- Add a "Smart Wrapper Parameter" with:
- Control Parameter: ADVANCED_MODE
- Condition: equals
- Control Value: true
- Referenced Parameters: CACHE_TTL,RETRY_COUNT,TIMEOUT_SECONDS
This will show or hide the CACHE_TTL, RETRY_COUNT, and TIMEOUT_SECONDS parameters when ADVANCED_MODE is set to "true".
The plugin adds JavaScript to your Jenkins build forms that:
- Monitors changes to parameter values
- Evaluates conditions for each smart parameter and wrapper
- Updates the visibility of parameters in real-time
- equals: The control parameter value must exactly match the control value
- notEquals: The control parameter value must not match the control value
- contains: The control parameter value must contain the control value as a substring
- startsWith: The control parameter value must start with the control value
- endsWith: The control parameter value must end with the control value
- regex: The control parameter value must match the regular expression pattern in the control value
To build and test the plugin locally:
# Run a local Jenkins instance with the plugin
mvn hpi:run -Dport=5000
# Build the plugin package
mvn clean packageThe generated .hpi file can be found in the target/ directory.
Please report issues and enhancement requests in the Jenkins issue tracker.
Contributions are welcome! Please refer to our contribution guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.