Class ParametersAction
- java.lang.Object
-
- hudson.model.ParametersAction
-
- All Implemented Interfaces:
Action
,EnvironmentContributingAction
,LabelAssignmentAction
,ModelObject
,Queue.QueueAction
,Iterable<ParameterValue>
,RunAction2
@ExportedBean public class ParametersAction extends Object implements RunAction2, Iterable<ParameterValue>, Queue.QueueAction, EnvironmentContributingAction, LabelAssignmentAction
Records the parameter values used for a build.This object is associated with the build record so that we remember what parameters were used for what build. It is also attached to the queue item to remember parameter that were specified when scheduling.
-
-
Field Summary
Fields Modifier and Type Field Description static String
KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME
Three state variable (null, false, true).static String
SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME
-
Constructor Summary
Constructors Constructor Description ParametersAction(ParameterValue... parameters)
ParametersAction(List<ParameterValue> parameters)
ParametersAction(List<ParameterValue> parameters, Collection<String> additionalSafeParameters)
Constructs a new action with additional safe parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildEnvironment(Run<?,?> run, EnvVars env)
Called byRun
to allow plugins to contribute environment variables.void
createBuildWrappers(AbstractBuild<?,?> build, Collection<? super BuildWrapper> result)
ParametersAction
createUpdated(Collection<? extends ParameterValue> overrides)
Creates a newParametersAction
that contains all the parameters in this action with the overrides / new values given as parameters.VariableResolver<String>
createVariableResolver(AbstractBuild<?,?> build)
Creates anVariableResolver
that aggregates all the parameters.List<ParameterValue>
getAllParameters()
Returns all parameters.Label
getAssignedLabel(SubTask task)
Reassigns where the task gets run.String
getDisplayName()
Gets the string to be displayed.String
getIconFileName()
Gets the name of the icon.ParameterValue
getParameter(String name)
List<ParameterValue>
getParameters()
String
getUrlName()
Gets the URL path name.Iterator<ParameterValue>
iterator()
ParametersAction
merge(ParametersAction overrides)
void
onAttached(Run<?,?> r)
Called when this action is added to a build.void
onLoad(Run<?,?> r)
Called after a build is loaded to which this action was previously attached.boolean
shouldSchedule(List<Action> actions)
Allow an other build of the same project to be scheduled, if it has other parameters.String
substitute(AbstractBuild<?,?> build, String text)
Performs a variable substitution to the given text and return it.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface hudson.model.EnvironmentContributingAction
buildEnvVars
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final String KEEP_UNDEFINED_PARAMETERS_SYSTEM_PROPERTY_NAME
Three state variable (null, false, true). If explicitly set to true, it will keep all variable, explicitly set to false it will drop all of them (except if they are marked safe). If null, and they are not safe, it will log a warning in logs to the user to let him choose the behavior- Since:
- 2.3
-
SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final String SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME
-
-
Constructor Detail
-
ParametersAction
public ParametersAction(@NonNull List<ParameterValue> parameters)
-
ParametersAction
public ParametersAction(List<ParameterValue> parameters, Collection<String> additionalSafeParameters)
Constructs a new action with additional safe parameters. The additional safe parameters should be only those considered safe to override the environment and what is declared in the project config in addition to those specified by the user inSAFE_PARAMETERS_SYSTEM_PROPERTY_NAME
. See SECURITY-170- Parameters:
parameters
- the parametersadditionalSafeParameters
- additional safe parameters- Since:
- 1.651.2, 2.3
-
ParametersAction
public ParametersAction(ParameterValue... parameters)
-
-
Method Detail
-
createBuildWrappers
public void createBuildWrappers(AbstractBuild<?,?> build, Collection<? super BuildWrapper> result)
-
buildEnvironment
public void buildEnvironment(Run<?,?> run, EnvVars env)
Description copied from interface:EnvironmentContributingAction
Called byRun
to allow plugins to contribute environment variables.- Specified by:
buildEnvironment
in interfaceEnvironmentContributingAction
- Parameters:
run
- The calling build. Never null.env
- Environment variables should be added to this map.
-
substitute
public String substitute(AbstractBuild<?,?> build, String text)
Performs a variable substitution to the given text and return it.
-
createVariableResolver
public VariableResolver<String> createVariableResolver(AbstractBuild<?,?> build)
Creates anVariableResolver
that aggregates all the parameters.If you are a
BuildStep
, most likely you should callAbstractBuild.getBuildVariableResolver()
.
-
iterator
public Iterator<ParameterValue> iterator()
- Specified by:
iterator
in interfaceIterable<ParameterValue>
-
getParameters
@Exported(visibility=2) public List<ParameterValue> getParameters()
-
getParameter
public ParameterValue getParameter(String name)
-
getAssignedLabel
public Label getAssignedLabel(SubTask task)
Description copied from interface:LabelAssignmentAction
Reassigns where the task gets run.- Specified by:
getAssignedLabel
in interfaceLabelAssignmentAction
- Parameters:
task
- Never null.- Returns:
- null to let other
LabelAssignmentAction
s take control, eventually toSubTask.getAssignedLabel()
. If non-null value is returned, that label will be authoritative.
-
getDisplayName
public String getDisplayName()
Description copied from interface:Action
Gets the string to be displayed. The convention is to capitalize the first letter of each word, such as "Test Result".- Specified by:
getDisplayName
in interfaceAction
- Specified by:
getDisplayName
in interfaceModelObject
- Returns:
- Can be null in case the action is hidden.
-
getIconFileName
public String getIconFileName()
Description copied from interface:Action
Gets the name of the icon.- Specified by:
getIconFileName
in interfaceAction
- Returns:
- If the icon name is prefixed with "symbol-", a Jenkins Symbol
will be used.
If just a file name (like "abc.gif") is returned, it will be interpreted as a file name inside
/images/24x24
. This is useful for using one of the stock images.If an absolute file name that starts from '/' is returned (like "/plugin/foo/abc.gif"), then it will be interpreted as a path from the context root of Jenkins. This is useful to pick up image files from a plugin.
Finally, return null to hide it from the task list. This is normally not very useful, but this can be used for actions that only contribute
floatBox.jelly
and no task list item. The other case where this is useful is to avoid showing links that require a privilege when the user is anonymous. - See Also:
- Jenkins Symbols,
Functions.isAnonymous()
,Functions.getIconFilePath(Action)
-
getUrlName
public String getUrlName()
Description copied from interface:Action
Gets the URL path name.For example, if this method returns "xyz", and if the parent object (that this action is associated with) is bound to /foo/bar/zot, then this action object will be exposed to /foo/bar/zot/xyz.
This method should return a string that's unique among other
Action
s.The returned string can be an absolute URL, like "http://www.sun.com/", which is useful for directly connecting to external systems.
If the returned string starts with '/', like '/foo', then it's assumed to be relative to the context path of the Jenkins webapp.
- Specified by:
getUrlName
in interfaceAction
- Returns:
- null if this action object doesn't need to be bound to web
(when you do that, be sure to also return null from
Action.getIconFileName()
. - See Also:
Functions.getActionUrl(String, Action)
-
shouldSchedule
public boolean shouldSchedule(List<Action> actions)
Allow an other build of the same project to be scheduled, if it has other parameters.- Specified by:
shouldSchedule
in interfaceQueue.QueueAction
-
createUpdated
@NonNull public ParametersAction createUpdated(Collection<? extends ParameterValue> overrides)
Creates a newParametersAction
that contains all the parameters in this action with the overrides / new values given as parameters.- Returns:
- New
ParametersAction
. The result may contain nullParameterValue
s
-
merge
@NonNull public ParametersAction merge(@CheckForNull ParametersAction overrides)
-
onAttached
public void onAttached(Run<?,?> r)
Description copied from interface:RunAction2
Called when this action is added to a build.- Specified by:
onAttached
in interfaceRunAction2
-
onLoad
public void onLoad(Run<?,?> r)
Description copied from interface:RunAction2
Called after a build is loaded to which this action was previously attached.- Specified by:
onLoad
in interfaceRunAction2
-
getAllParameters
public List<ParameterValue> getAllParameters()
Returns all parameters. Be careful in how you process them. It will return parameters even not being defined asParametersDefinitionProperty
in the job, so any external caller could inject any parameter (using any key) here. Treat it as untrusted data.- Returns:
- all parameters defined here.
- Since:
- 1.651.2, 2.3
-
-