Class CommandInterpreter
- java.lang.Object
-
- hudson.tasks.BuildStepCompatibilityLayer
-
- hudson.tasks.Builder
-
- hudson.tasks.CommandInterpreter
-
- All Implemented Interfaces:
ExtensionPoint
,Describable<Builder>
,BuildStep
,EnvVarsFilterableBuilder
public abstract class CommandInterpreter extends Builder implements EnvVarsFilterableBuilder
- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.tasks.BuildStep
BuildStep.PublisherList
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
Fields Modifier and Type Field Description protected String
command
Command to execute.protected List<EnvVarsFilterLocalRule>
configuredLocalRules
List of configured environment filter rules-
Fields inherited from interface hudson.tasks.BuildStep
BUILDERS, PUBLISHERS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CommandInterpreter(String command)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract String[]
buildCommandLine(FilePath script)
List<EnvVarsFilterLocalRule>
buildEnvVarsFilterRules()
The order is respected for the execution.FilePath
createScriptFile(FilePath dir)
Creates a script file in a temporary name in the specified directory.String
getCommand()
List<EnvVarsFilterLocalRule>
getConfiguredLocalRules()
protected abstract String
getContents()
protected abstract String
getFileExtension()
protected boolean
isErrorlevelForUnstableBuild(int exitCode)
Determines whether a non-zero exit code from the process should change the build status toResult.UNSTABLE
instead of defaultResult.FAILURE
.protected int
join(Proc p)
Reports the exit code from the process.boolean
perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)
Runs the step over the given build and reports the progress to the listener.boolean
perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener)
-
Methods inherited from class hudson.tasks.Builder
all, getDescriptor, getRequiredMonitorService, prebuild
-
Methods inherited from class hudson.tasks.BuildStepCompatibilityLayer
getProjectAction, getProjectAction, getProjectActions, perform, prebuild
-
-
-
-
Field Detail
-
command
protected final String command
Command to execute. The format depends on the actualCommandInterpreter
implementation.
-
configuredLocalRules
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) protected List<EnvVarsFilterLocalRule> configuredLocalRules
List of configured environment filter rules
-
-
Constructor Detail
-
CommandInterpreter
protected CommandInterpreter(String command)
-
-
Method Detail
-
getCommand
public final String getCommand()
-
buildEnvVarsFilterRules
@NonNull public List<EnvVarsFilterLocalRule> buildEnvVarsFilterRules()
Description copied from interface:EnvVarsFilterableBuilder
The order is respected for the execution. Local rules will be executed before the global ones. This method is called only once per step to create theEnvVarsFilterRuleContext
. The default implementation returns an empty list; this allows build steps to support global rules.- Specified by:
buildEnvVarsFilterRules
in interfaceEnvVarsFilterableBuilder
-
getConfiguredLocalRules
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public List<EnvVarsFilterLocalRule> getConfiguredLocalRules()
-
perform
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException
Description copied from interface:BuildStep
Runs the step over the given build and reports the progress to the listener.A plugin can contribute the action object to
Actionable.getActions()
so that a 'report' becomes a part of the persisted data ofBuild
. This is how JUnit plugin attaches the test report to a build page, for example.When this build step needs to make (direct or indirect) permission checks to
ACL
(for example, to locate other projects by name, build them, or access their artifacts) then it must be run under a specificAuthentication
. In such a case, the implementation should check whetherJenkins.getAuthentication2()
isACL.SYSTEM2
, and if so, replace it for the duration of this step withJenkins.ANONYMOUS
. (Either usingACL.impersonate2(org.springframework.security.core.Authentication)
, or by making explicit calls toACL.hasPermission2(Authentication, Permission)
.) This would typically happen when noQueueItemAuthenticator
was available, configured, and active.- Specified by:
perform
in interfaceBuildStep
- Overrides:
perform
in classBuildStepCompatibilityLayer
- Returns:
- Delegates to
SimpleBuildStep.perform(Run, FilePath, Launcher, TaskListener)
if possible, always returning true or throwing an error. - Throws:
InterruptedException
- If the build is interrupted by the user (in an attempt to abort the build.) Normally theBuildStep
implementations may simply forward the exception it got from its lower-level functions.
-
isErrorlevelForUnstableBuild
protected boolean isErrorlevelForUnstableBuild(int exitCode)
Determines whether a non-zero exit code from the process should change the build status toResult.UNSTABLE
instead of defaultResult.FAILURE
. Changing toResult.UNSTABLE
does not abort the build, next steps are continued.- Since:
- 2.26
-
perform
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException
- Throws:
InterruptedException
-
join
protected int join(Proc p) throws IOException, InterruptedException
Reports the exit code from the process. This allows subtypes to treat the exit code differently (for example by treating non-zero exit code as if it's zero, or to set the status toResult.UNSTABLE
). Any non-zero exit code will cause the build step to fail. UseisErrorlevelForUnstableBuild(int exitCode)
to redefine the default behaviour.- Throws:
IOException
InterruptedException
- Since:
- 1.549
-
createScriptFile
public FilePath createScriptFile(@NonNull FilePath dir) throws IOException, InterruptedException
Creates a script file in a temporary name in the specified directory.- Throws:
IOException
InterruptedException
-
getContents
protected abstract String getContents()
-
getFileExtension
protected abstract String getFileExtension()
-
-