2 | A message that will be logged to the console. The message will also be
3 | associated with the stage result and may be shown in visualizations.
4 |
2 | Archives build output artifacts for later use.
3 | As of Jenkins 2.x, this step is deprecated in favor of the more configurable archiveArtifacts.
4 |
2 | A message that will be logged to the console if an error is caught. The
3 | message will also be associated with the stage result and may be shown in
4 | visualizations.
5 |
2 | Signals an error.
3 | Useful if you want to conditionally abort some part of your program.
4 | You can also just throw new Exception(),
5 | but this step will avoid printing a stack trace.
6 |
7 |
--------------------------------------------------------------------------------
/src/test/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStepTest/serialFormWhenBuildResultOptionDidNotExist.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/workflow-basic-steps-plugin/HEAD/src/test/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStepTest/serialFormWhenBuildResultOptionDidNotExist.zip
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/GetContextStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | No snippet generation supported. See inline help for usage.
5 |
6 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/WithContextStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | No snippet generation supported. See inline help for usage.
5 |
6 |
--------------------------------------------------------------------------------
/src/test/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStepTest/serialFormWhenTypeOfBuildResultFieldWasResult.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jenkinsci/workflow-basic-steps-plugin/HEAD/src/test/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStepTest/serialFormWhenTypeOfBuildResultFieldWasResult.zip
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStep/help-message.html:
--------------------------------------------------------------------------------
1 |
2 | A message that will be logged to the console if an error is caught. If the
3 | stage result is specified, the message will also be associated with that
4 | result and may be shown in visualizations.
5 |
2 | Prints a message to the log and sets the overall build result and the stage
3 | result to UNSTABLE. The message will also be associated with
4 | the stage result and may be shown in visualizations.
5 |
2 | Conditions under which the block should be retried.
3 | If none match, the block will fail.
4 | If there are no specified conditions,
5 | the block will always be retried except in case of user aborts.
6 |
2 | Simply pauses the Pipeline build until the given amount of time has expired.
3 | Equivalent to (on Unix) sh 'sleep …'.
4 | May be used to pause one branch of parallel while another proceeds.
5 |
2 | Sets the initial wait period, in milliseconds, between retries. Defaults to 250ms.
3 |
4 | Each failure will slow down the delay between attempts up to a maximum of 15 seconds.
5 |
2 | The encoding to use when reading the file.
3 | If left blank, the platform default encoding will be used.
4 | Binary files can be read into a Base64-encoded string by specifying "Base64" as the encoding.
5 |
2 | Recursively deletes the current directory and its contents.
3 | Symbolic links and junctions will not be followed but will be removed.
4 | To delete a specific directory of a workspace wrap the deleteDir
5 | step in a dir step.
6 |
2 | The target encoding for the file.
3 | If left blank, the platform default encoding will be used.
4 | If the text is a Base64-encoded string, the decoded binary data can be written
5 | to the file by specifying "Base64" as the encoding.
6 |
2 | Optional set of Ant-style exclude patterns.
3 | Use a comma separated list to add more than one expression.
4 | If blank, no files will be excluded.
5 |
2 | Retry the block (up to N times) if any exception happens during its body execution.
3 | If an exception happens on the final attempt then it will lead to aborting the build (unless it is caught and processed somehow).
4 | User aborts of the build are not caught.
5 |
2 | Executes the code inside the block with a determined time out limit.
3 | If the time limit is reached, an exception (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) is thrown, which leads to aborting
4 | the build (unless it is caught and processed somehow).
5 |
2 | Binds a tool installation to a variable (the tool home directory is returned).
3 | Only tools already configured in Configure System are available here. If the original tool installer
4 | has the auto-provision feature, then the tool will be installed as required.
5 |
2 | If an error is caught, the stage result will be set to this value. If a
3 | message was specified, the message will be associated with this result.
4 | Use SUCCESS or null to keep the stage result from
5 | being set when an error is caught.
6 |
7 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | /*
2 | See the documentation for more options:
3 |
4 | https://github.com/jenkins-infra/pipeline-library/
5 |
6 | */
7 | buildPlugin(
8 | useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests
9 | configurations: [
10 | [platform: 'linux', jdk: 21],
11 | [platform: 'windows', jdk: 17],
12 | [platform: 'linux', jdk: 25],
13 | ])
14 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/EnvStep/help-overrides.html:
--------------------------------------------------------------------------------
1 |
2 | A list of environment variables to set, each in the form VARIABLE=value
3 | or VARIABLE= to unset variables otherwise defined.
4 | You may also use the syntax PATH+WHATEVER=/something
5 | to prepend /something to $PATH.
6 |
3 | This is a special step that allows to call builders or post-build actions (as in freestyle or similar projects), in general "build steps".
4 | Just select the build step to call from the dropdown list and configure it as needed.
5 |
6 |
7 | Note that only Pipeline-compatible steps will be shown in the list.
8 |
2 | Runs its body repeatedly until it returns true.
3 | If it returns false, waits a while and tries again.
4 | (Subsequent failures will slow down the delay between attempts up to a maximum of 15 seconds.)
5 | There is no limit to the number of retries,
6 | but if the body throws an error that is thrown up immediately.
7 |
2 | If an error is caught, the overall build result will be set to this value.
3 | Note that the build result can only get worse, so you cannot change the result
4 | to SUCCESS if the current result is UNSTABLE or worse.
5 | Use SUCCESS or null to keep the build result from
6 | being set when an error is caught.
7 |
2 | If selected, return a temporary directory associated with the current directory path rather than the directory path itself.
3 | The return value is different for each current directory. No two directories share the same temporary directory.
4 | This is an appropriate place to put temporary files which should not clutter a source checkout;
5 | local repositories or caches; etc. Defaults to false.
6 |
3 | This is a special step that allows to call build wrappers (also called "Environment Configuration" in freestyle or similar projects).
4 | Just select the wrapper to use from the dropdown list and configure it as needed. Everything inside the wrapper block is under its effect.
5 |
6 |
7 | Note that only Pipeline-compatible wrappers will be shown in the list.
8 |
2 | Executes its body, and if an exception is thrown, sets the overall build result
3 | and the stage result to UNSTABLE, prints a specified message and
4 | the thrown exception to the build log, and associates the stage result with the
5 | message so that it can be displayed by visualizations.
6 |
Equivalent to catchError(message: message, buildResult: 'UNSTABLE', stageResult: 'UNSTABLE').
7 |
2 | If true, certain types of exceptions that are used to interrupt the flow of
3 | execution for Pipelines will be caught and handled by the step. If false,
4 | those types of exceptions will be caught and immediately rethrown. Examples
5 | of these types of exceptions include those thrown when a build is manually
6 | aborted through the UI and those thrown by the timeout step. Defaults to true.
7 |
2 | If true, certain types of exceptions that are used to interrupt the flow of
3 | execution for Pipelines will be caught and handled by the step. If false,
4 | those types of exceptions will be caught and immediately rethrown. Examples
5 | of these types of exceptions include those thrown when a build is manually
6 | aborted through the UI and those thrown by the timeout step. Defaults to true.
7 |
8 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/Messages.properties:
--------------------------------------------------------------------------------
1 | ArtifactArchiverStepExecution.Deprecated=The archive step is deprecated, please use archiveArtifacts instead.
2 | ArtifactArchiverStepExecution.NoFiles=No files found to archive for pattern "{0}"; continuing.
3 | ArtifactArchiverStepExecution.NoFilesWithExcludes=No files found to archive for pattern "{0}", excluding "{1}"; continuing.
4 | FileExistsStep.EmptyString=The fileExists step was called with a null or empty string, so the current directory will be checked instead.
5 |
--------------------------------------------------------------------------------
/src/test/resources/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 |
6 |
7 |
10 | true
11 |
12 |
13 | false
14 |
15 |
--------------------------------------------------------------------------------
/src/test/resources/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/workflow/4.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 3
6 |
7 | 4
8 | org.jenkinsci.plugins.workflow.steps.TimeoutStep
9 |
10 |
11 |
12 |
13 | 1547839656316
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/jenkins-security-scan.yml:
--------------------------------------------------------------------------------
1 | name: Jenkins Security Scan
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | types: [ opened, synchronize, reopened ]
9 | workflow_dispatch:
10 |
11 | permissions:
12 | security-events: write
13 | contents: read
14 | actions: read
15 |
16 | jobs:
17 | security-scan:
18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
19 | with:
20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.
22 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stash/StashStep/help-includes.html:
--------------------------------------------------------------------------------
1 |
2 | Optional set of Ant-style include patterns.
3 | Use a comma separated list to add more than one expression.
4 | If blank, treated like **: all files.
5 | The current working directory is the base directory for the saved files,
6 | which will later be restored in the same relative locations,
7 | so if you want to use a subdirectory wrap this in dir.
8 |
2 | The Jenkins controller was restarted while the build was running a step which cannot be resumed.
3 | Some steps like sh or input are written to survive a Jenkins restart
4 | and simply pick up where they left off when the build resumes.
5 | Others like checkout or junit normally complete promptly but cannot tolerate a restart.
6 | In case one of these steps happened to be in progress when Jenkins shut down,
7 | the resumed build will throw an error;
8 | using this condition with retry allows the step (or the whole enclosing node block) to be rerun.
9 |
2 | Sets one or more environment variables within a block.
3 | The names of environment variables are case-insensitive but case-preserving, that is, setting `Foo` will change the value of `FOO` if it already exists.
4 | Environment variables are available to any external processes spawned within that scope.
5 | For example:
6 |
(Note that here we are using single quotes in Groovy, so the variable expansion is being done by the Bourne shell, not Jenkins.)
14 |
See the documentation for the env singleton for more information on environment variables.
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Pipeline: Basic Steps Plugin
2 |
3 | ## Introduction
4 |
5 | Commonly used steps for Pipelines. General Jenkins Pipeline documentation is available in the [Pipeline chapter](https://www.jenkins.io/doc/book/pipeline/) of the [User Handbook](https://www.jenkins.io/doc/book/getting-started/).
6 |
7 | The [Pipeline steps reference](https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/) describes the Pipeline steps provided by this plugin.
8 |
9 | The [Pipeline solutions page](https://www.jenkins.io/solutions/pipeline/) provides videos, tutorials, and other Pipeline resources.
10 |
11 | ## Version History
12 |
13 | New versions use [GitHub Releases](https://github.com/jenkinsci/workflow-basic-steps-plugin/releases).
14 | See also the [archive](https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/bed5ff08317e278d5d8cb15105b6579911568f8c/CHANGELOG.md).
15 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/WithContextStep/help.html:
--------------------------------------------------------------------------------
1 |
2 | Wraps a block in a contextual object as in BodyInvoker.withContext; cf. getContext.
3 | Takes a single context argument plus a block. Example:
4 |
5 |
withContext(new MyConsoleLogFilter()) {
6 | sh 'process'
7 | }
8 |
9 | Automatically merges its argument with contextual objects in the case of ConsoleLogFilter, LauncherDecorator, and EnvironmentExpander.
10 |
11 |
12 | For use from trusted code, such as global libraries, which can manipulate internal Jenkins APIs.
13 |
14 |
15 | Do not attempt to pass objects defined in Groovy;
16 | only Java-defined objects are supported.
17 | Really you should avoid using this and getContext and just define a Step in a plugin instead.
18 |
2 | Saves a set of files for later use on any node/workspace in the same Pipeline run.
3 | By default, stashed files are discarded at the end of a pipeline run.
4 | Other plugins may change this behavior to preserve stashes for longer.
5 | For example, Declarative Pipeline includes a preserveStashes() option
6 | to allow stashes from a run to be retained and used if that run is restarted.
7 |
8 | Stashes from one Pipeline run are not available in other runs, other Pipelines, or other jobs.
9 | If you want to persist artifacts for use outside of a single run, consider using
10 |
11 | archiveArtifacts instead.
12 | Note that the stash and unstash steps are designed for use with small files.
13 | For large data transfers, use the External Workspace Manager plugin,
14 | or use an external repository manager such as Nexus or Artifactory.
15 | This is because stashed files are archived in a compressed TAR, and with large files this demands considerable
16 | resources on the controller, particularly CPU time.
17 | There's not a hard stash size limit, but between 5-100 MB you should probably consider alternatives.
18 | If you use the Artifact Manager on S3 plugin, or another plugin with a remote atifact manager,
19 | you can use this step without affecting controller performance
20 | since stashes will be sent directly to S3 from the agent (and similarly for unstash).
21 |
22 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/TimeoutStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/WriteFileStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/test/resources/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | 1
9 |
10 |
11 |
12 |
13 | 1
14 | 1547839655961
15 | 1547839655963
16 | 0
17 | UTF-8
18 | false
19 |
20 | SUCCESS
21 |
24 |
25 | MAX_SURVIVABILITY
26 |
27 |
28 | flowNode
29 | 20637465
30 |
31 |
32 | classLoad
33 | 57883475
34 |
35 |
36 | run
37 | 299403380
38 |
39 |
40 | parse
41 | 83564469
42 |
43 |
44 | saveProgram
45 | 101383291
46 |
47 |
48 | true
49 | 5
50 | 1:5
51 | 2
52 | false
53 | false
54 |
55 | false
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stash/StashStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/ArtifactUnarchiverStep.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.workflow.steps;
2 |
3 | import edu.umd.cs.findbugs.annotations.NonNull;
4 | import hudson.Extension;
5 | import hudson.FilePath;
6 | import hudson.model.Run;
7 | import hudson.model.TaskListener;
8 | import java.util.Collections;
9 | import java.util.HashSet;
10 | import java.util.Map;
11 | import java.util.Set;
12 | import org.kohsuke.stapler.DataBoundConstructor;
13 | import org.kohsuke.stapler.DataBoundSetter;
14 |
15 | /**
16 | * @author Kohsuke Kawaguchi
17 | */
18 | public class ArtifactUnarchiverStep extends Step {
19 | /**
20 | * Files to copy over.
21 | */
22 | @DataBoundSetter
23 | public Map mapping;
24 |
25 | // TBD: alternate single-file option value ~ Collections.singletonMap(value, value)
26 |
27 | @DataBoundConstructor
28 | public ArtifactUnarchiverStep() {}
29 |
30 | @Override
31 | public StepExecution start(StepContext context) throws Exception {
32 | return new ArtifactUnarchiverStepExecution(mapping, context);
33 | }
34 |
35 | @Extension
36 | public static class DescriptorImpl extends StepDescriptor {
37 |
38 | @Override
39 | public String getFunctionName() {
40 | return "unarchive";
41 | }
42 |
43 | @NonNull
44 | @Override
45 | public String getDisplayName() {
46 | return "Copy archived artifacts into the workspace";
47 | }
48 |
49 | @Override
50 | public boolean isAdvanced() {
51 | return true;
52 | }
53 |
54 | @Override
55 | public Set extends Class>> getRequiredContext() {
56 | Set> context = new HashSet<>();
57 | Collections.addAll(context, FilePath.class, Run.class, TaskListener.class);
58 | return Collections.unmodifiableSet(context);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/PushdStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2014 Jesse Glick.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | /**
28 | * @deprecated Only exists as a placeholder for old running builds; now {@code org.jenkinsci.plugins.workflow.support.steps.PushdStep}.
29 | */
30 | @Deprecated
31 | public class PushdStep {
32 |
33 | private PushdStep() {}
34 |
35 | public static class Execution extends AbstractStepExecutionImpl {
36 |
37 | private Execution() {
38 | throw new AssertionError("only deserialized");
39 | }
40 |
41 | @Override
42 | public boolean start() throws Exception {
43 | throw new AssertionError("only deserialized");
44 | }
45 |
46 | @Override
47 | public void onResume() {}
48 |
49 | private static final long serialVersionUID = 1L;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/ArtifactUnarchiverStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 | Currently no visual configuration.
31 | May take a mapping parameter which is a map from artifact names (files, directories ending in /, or any other Ant patternsets),
32 | to workspace destination names.
33 | For example to copy one file:
34 |
35 |
unarchive mapping: ['target/my.war': 'here.war']
36 |
37 | To copy a whole directory:
38 |
39 |
unarchive mapping: ['dir/' : '.']
40 | sh 'cat dir/file'
41 |
42 | Replaced for most purposes by stash and unstash.
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/workflow/steps/IsUnixStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2015 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
28 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
29 | import org.junit.jupiter.api.BeforeEach;
30 | import org.junit.jupiter.api.Test;
31 | import org.jvnet.hudson.test.JenkinsRule;
32 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
33 |
34 | @WithJenkins
35 | class IsUnixStepTest {
36 |
37 | private JenkinsRule r;
38 |
39 | @BeforeEach
40 | void beforeEach(JenkinsRule rule) {
41 | r = rule;
42 | }
43 |
44 | @Test
45 | void basics() throws Exception {
46 | WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
47 | p.setDefinition(new CpsFlowDefinition(
48 | "def xsh(cmd) {if (isUnix()) {sh cmd} else {bat cmd}}; node {xsh 'echo hello world'}", true));
49 | r.assertLogContains("hello world", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/MailStep/config.jelly:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/SynchronousResumeNotSupportedErrorCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2022 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import hudson.Extension;
28 | import java.io.IOException;
29 | import org.jenkinsci.Symbol;
30 | import org.jenkinsci.plugins.workflow.flow.ErrorCondition;
31 | import org.kohsuke.stapler.DataBoundConstructor;
32 |
33 | /**
34 | * Checks for {@link SynchronousResumeNotSupportedException}.
35 | */
36 | public final class SynchronousResumeNotSupportedErrorCondition extends ErrorCondition {
37 |
38 | @DataBoundConstructor
39 | public SynchronousResumeNotSupportedErrorCondition() {}
40 |
41 | @Override
42 | public boolean test(Throwable error, StepContext context) throws IOException, InterruptedException {
43 | return error instanceof SynchronousResumeNotSupportedException;
44 | }
45 |
46 | @Symbol("nonresumable")
47 | @Extension
48 | public static final class DescriptorImpl extends ErrorConditionDescriptor {
49 |
50 | @Override
51 | public String getDisplayName() {
52 | return "Non-resumable steps";
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/ArtifactArchiverStep.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.workflow.steps;
2 |
3 | import edu.umd.cs.findbugs.annotations.NonNull;
4 | import hudson.Extension;
5 | import hudson.FilePath;
6 | import hudson.Launcher;
7 | import hudson.Util;
8 | import hudson.model.Run;
9 | import hudson.model.TaskListener;
10 | import java.util.Collections;
11 | import java.util.HashSet;
12 | import java.util.Set;
13 | import org.kohsuke.stapler.DataBoundConstructor;
14 | import org.kohsuke.stapler.DataBoundSetter;
15 |
16 | /**
17 | * Artifact archiving.
18 | *
19 | * @author Kohsuke Kawaguchi
20 | */
21 | public class ArtifactArchiverStep extends Step {
22 |
23 | private final String includes;
24 | private String excludes;
25 |
26 | @DataBoundConstructor
27 | public ArtifactArchiverStep(String includes) {
28 | this.includes = includes;
29 | }
30 |
31 | public String getIncludes() {
32 | return includes;
33 | }
34 |
35 | public String getExcludes() {
36 | return excludes;
37 | }
38 |
39 | @DataBoundSetter
40 | public void setExcludes(String excludes) {
41 | this.excludes = Util.fixEmptyAndTrim(excludes);
42 | }
43 |
44 | @Override
45 | public StepExecution start(StepContext context) throws Exception {
46 | return new ArtifactArchiverStepExecution(this, context);
47 | }
48 |
49 | @Extension
50 | public static class DescriptorImpl extends StepDescriptor {
51 |
52 | @Override
53 | public String getFunctionName() {
54 | return "archive";
55 | }
56 |
57 | @NonNull
58 | @Override
59 | public String getDisplayName() {
60 | return "Archive artifacts";
61 | }
62 |
63 | /**
64 | * When the {@code archiveArtifacts} symbol is available, {@link CoreStep} may be used instead,
65 | * with no more verbose a syntax but more configuration options.
66 | */
67 | @Override
68 | public boolean isAdvanced() {
69 | return true;
70 | }
71 |
72 | @Override
73 | public Set extends Class>> getRequiredContext() {
74 | Set> context = new HashSet<>();
75 | Collections.addAll(context, FilePath.class, Run.class, Launcher.class, TaskListener.class);
76 | return Collections.unmodifiableSet(context);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/resources/org/jenkinsci/plugins/workflow/steps/CatchErrorStep/help.html:
--------------------------------------------------------------------------------
1 |
2 | If the body throws an exception, mark the build as a failure, but nonetheless
3 | continue to execute the Pipeline from the statement following the catchError step.
4 | The behavior of the step when an exception is thrown can be configured to print
5 | a message, set a build result other than failure, change the stage result,
6 | or ignore certain kinds of exceptions that are used to interrupt the build.
7 |
This step is most useful when used in Declarative Pipeline or with the
8 | options to set the stage result or ignore build interruptions. Otherwise,
9 | consider using plain try-catch(-finally) blocks.
10 | It is also useful when using certain post-build actions (notifiers)
11 | originally defined for freestyle projects which pay attention to the result of the ongoing build.
12 |
If the shell step fails, the Pipeline build’s status will be set to failed, so that the subsequent mail step will see that this build is failed.
21 | In the case of the mail sender, this means that it will send mail.
22 | (It may also send mail if this build succeeded but previous ones failed, and so on.)
23 | Even in that case, this step can be replaced by the following idiom:
24 |
53 |
--------------------------------------------------------------------------------
/src/test/java/org/jenkinsci/plugins/workflow/steps/WithContextStepTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2016 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
28 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
29 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
30 | import org.junit.jupiter.api.BeforeEach;
31 | import org.junit.jupiter.api.Test;
32 | import org.junit.jupiter.api.extension.RegisterExtension;
33 | import org.jvnet.hudson.test.JenkinsRule;
34 | import org.jvnet.hudson.test.junit.jupiter.BuildWatcherExtension;
35 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
36 |
37 | @WithJenkins
38 | class WithContextStepTest {
39 |
40 | @SuppressWarnings("unused")
41 | @RegisterExtension
42 | private static final BuildWatcherExtension BUILD_WATCHER = new BuildWatcherExtension();
43 |
44 | private JenkinsRule r;
45 |
46 | @BeforeEach
47 | void beforeEach(JenkinsRule rule) {
48 | r = rule;
49 | }
50 |
51 | @Test
52 | void pushd() throws Exception {
53 | WorkflowJob p = r.createProject(WorkflowJob.class, "p");
54 | ScriptApproval.get().approveSignature("method hudson.FilePath child java.lang.String");
55 | p.setDefinition(new CpsFlowDefinition(
56 | "node {withContext(getContext(hudson.FilePath).child('subdir')) {echo(/simulating dir step in ${pwd()}/)}}",
57 | true));
58 | r.assertLogContains(
59 | "simulating dir step in "
60 | + r.jenkins.getWorkspaceFor(p).child("subdir").getRemote(),
61 | r.buildAndAssertSuccess(p));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/IsUnixStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2015 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import hudson.Extension;
29 | import hudson.Launcher;
30 | import java.util.Collections;
31 | import java.util.Set;
32 | import org.kohsuke.stapler.DataBoundConstructor;
33 |
34 | /**
35 | * Checks whether we are running on Unix.
36 | */
37 | public class IsUnixStep extends Step {
38 |
39 | @DataBoundConstructor
40 | public IsUnixStep() {}
41 |
42 | @Override
43 | public StepExecution start(StepContext context) throws Exception {
44 | return new Execution(context);
45 | }
46 |
47 | public static class Execution extends SynchronousStepExecution {
48 |
49 | Execution(StepContext context) {
50 | super(context);
51 | }
52 |
53 | @Override
54 | protected Boolean run() throws Exception {
55 | return getContext().get(Launcher.class).isUnix();
56 | }
57 |
58 | private static final long serialVersionUID = 1L;
59 | }
60 |
61 | @Extension
62 | public static final class DescriptorImpl extends StepDescriptor {
63 |
64 | @Override
65 | public String getFunctionName() {
66 | return "isUnix";
67 | }
68 |
69 | @NonNull
70 | @Override
71 | public String getDisplayName() {
72 | return "Checks if running on a Unix-like node";
73 | }
74 |
75 | @Override
76 | public Set extends Class>> getRequiredContext() {
77 | return Collections.singleton(Launcher.class);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStep.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.workflow.steps;
2 |
3 | import edu.umd.cs.findbugs.annotations.NonNull;
4 | import hudson.Extension;
5 | import hudson.model.TaskListener;
6 | import hudson.util.ListBoxModel;
7 | import java.io.Serializable;
8 | import java.util.Collections;
9 | import java.util.Set;
10 | import java.util.concurrent.TimeUnit;
11 | import org.kohsuke.stapler.DataBoundConstructor;
12 | import org.kohsuke.stapler.DataBoundSetter;
13 |
14 | /**
15 | * Executes the body with a timeout, which will kill the body.
16 | *
17 | * @author Kohsuke Kawaguchi
18 | */
19 | public class TimeoutStep extends Step implements Serializable {
20 |
21 | private final int time;
22 |
23 | private TimeUnit unit = TimeUnit.MINUTES;
24 |
25 | private boolean activity = false;
26 |
27 | @DataBoundConstructor
28 | public TimeoutStep(int time) {
29 | this.time = time;
30 | }
31 |
32 | @DataBoundSetter
33 | public void setUnit(TimeUnit unit) {
34 | this.unit = unit;
35 | }
36 |
37 | public int getTime() {
38 | return time;
39 | }
40 |
41 | public TimeUnit getUnit() {
42 | return unit;
43 | }
44 |
45 | @DataBoundSetter
46 | public void setActivity(boolean activity) {
47 | this.activity = activity;
48 | }
49 |
50 | public boolean isActivity() {
51 | return activity;
52 | }
53 |
54 | @Override
55 | public DescriptorImpl getDescriptor() {
56 | return (DescriptorImpl) super.getDescriptor();
57 | }
58 |
59 | @Override
60 | public StepExecution start(StepContext context) throws Exception {
61 | return new TimeoutStepExecution(this, context);
62 | }
63 |
64 | @Extension
65 | public static class DescriptorImpl extends StepDescriptor {
66 |
67 | @Override
68 | public String getFunctionName() {
69 | return "timeout";
70 | }
71 |
72 | @Override
73 | public boolean takesImplicitBlockArgument() {
74 | return true;
75 | }
76 |
77 | @NonNull
78 | @Override
79 | public String getDisplayName() {
80 | return "Enforce time limit";
81 | }
82 |
83 | public ListBoxModel doFillUnitItems() {
84 | ListBoxModel r = new ListBoxModel();
85 | for (TimeUnit unit : TimeUnit.values()) {
86 | r.add(unit.name());
87 | }
88 | return r;
89 | }
90 |
91 | @Override
92 | public Set extends Class>> getRequiredContext() {
93 | return Collections.singleton(TaskListener.class);
94 | }
95 |
96 | // TODO argumentsToString as for SleepStep
97 |
98 | }
99 |
100 | private static final long serialVersionUID = 1L;
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/DeleteDirStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2015 Cloudbees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import hudson.Extension;
29 | import hudson.FilePath;
30 | import java.util.Collections;
31 | import java.util.Set;
32 | import org.kohsuke.stapler.DataBoundConstructor;
33 |
34 | /**
35 | * Simple step that will wipe out the current working directory in a workflows workspace.
36 | */
37 | public final class DeleteDirStep extends Step {
38 |
39 | @DataBoundConstructor
40 | public DeleteDirStep() {}
41 |
42 | @Override
43 | public StepExecution start(StepContext context) throws Exception {
44 | return new Execution(context);
45 | }
46 |
47 | @Extension
48 | public static final class DescriptorImpl extends StepDescriptor {
49 |
50 | @Override
51 | public String getFunctionName() {
52 | return "deleteDir";
53 | }
54 |
55 | @NonNull
56 | @Override
57 | public String getDisplayName() {
58 | return "Recursively delete the current directory from the workspace";
59 | }
60 |
61 | @Override
62 | public Set extends Class>> getRequiredContext() {
63 | return Collections.singleton(FilePath.class);
64 | }
65 | }
66 |
67 | public static final class Execution extends SynchronousNonBlockingStepExecution {
68 |
69 | Execution(StepContext context) {
70 | super(context);
71 | }
72 |
73 | @Override
74 | protected Void run() throws Exception {
75 | getContext().get(FilePath.class).deleteRecursive();
76 | return null;
77 | }
78 |
79 | private static final long serialVersionUID = 1L;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/ErrorStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2014 Jesse Glick.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import edu.umd.cs.findbugs.annotations.NonNull;
28 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
29 | import hudson.AbortException;
30 | import hudson.Extension;
31 | import java.util.Collections;
32 | import java.util.Set;
33 | import org.kohsuke.stapler.DataBoundConstructor;
34 |
35 | public final class ErrorStep extends Step {
36 |
37 | private final String message;
38 |
39 | @DataBoundConstructor
40 | public ErrorStep(String message) {
41 | this.message = message;
42 | }
43 |
44 | public String getMessage() {
45 | return message;
46 | }
47 |
48 | @Override
49 | public StepExecution start(StepContext context) throws Exception {
50 | return new Execution(message, context);
51 | }
52 |
53 | public static final class Execution extends SynchronousStepExecution {
54 |
55 | private static final long serialVersionUID = 1L;
56 |
57 | @SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Only used when starting.")
58 | private final transient String message;
59 |
60 | Execution(String message, StepContext context) {
61 | super(context);
62 | this.message = message;
63 | }
64 |
65 | @Override
66 | protected Void run() throws Exception {
67 | throw new AbortException(message);
68 | }
69 | }
70 |
71 | @Extension
72 | public static final class DescriptorImpl extends StepDescriptor {
73 |
74 | @Override
75 | public String getFunctionName() {
76 | return "error";
77 | }
78 |
79 | @NonNull
80 | @Override
81 | public String getDisplayName() {
82 | return "Error signal";
83 | }
84 |
85 | @Override
86 | public Set extends Class>> getRequiredContext() {
87 | return Collections.emptySet();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/CatchExecutionOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License
3 | *
4 | * Copyright 2019 CloudBees, Inc.
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package org.jenkinsci.plugins.workflow.steps;
26 |
27 | import edu.umd.cs.findbugs.annotations.CheckForNull;
28 | import edu.umd.cs.findbugs.annotations.NonNull;
29 | import hudson.model.Result;
30 | import java.io.Serializable;
31 | import org.jenkinsci.plugins.workflow.actions.WarningAction;
32 |
33 | public interface CatchExecutionOptions extends Serializable {
34 | /**
35 | * A message to be printed when an error is caught.
36 | *
37 | * If {@link #getStepResultOnError} (by adding a {@link WarningAction})
38 | */
39 | @CheckForNull
40 | String getMessage();
41 |
42 | /**
43 | * The result that will be used for setting the build result if an error is caught.
44 | *
45 | * Return {@link Result#SUCCESS} to leave the build result unchanged. If {@link #isCatchInterruptions}
46 | * returns {@code true}, then if a {@link FlowInterruptedException} is caught, its result will be used
47 | * instead of this value.
48 | */
49 | @NonNull
50 | Result getBuildResultOnError();
51 |
52 | /**
53 | * The result that will be used for annotating the with {@link WarningAction}) if an error is caught.
54 | *
55 | * Return {@link Result#SUCCESS} to leave the step result unchanged. If {@link #isCatchInterruptions}
56 | * returns {@code true}, then if a {@link FlowInterruptedException} is caught, its result will be used
57 | * instead of this value.
58 | */
59 | @NonNull
60 | Result getStepResultOnError();
61 |
62 | /**
63 | * Whether {@link FlowInterruptedException} should be caught and handled by the step or rethrown.
64 | *
65 | * {@link FlowInterruptedException} is commonly used to control the flow of execution for things
66 | * like builds aborted by a user and builds that time out inside of {@link TimeoutStep}. It is
67 | * sometimes desirable to rethrow these kinds of exceptions rather than catching them so as to
68 | * not interfere with their intended behavior.
69 | */
70 | boolean isCatchInterruptions();
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/jenkinsci/plugins/workflow/steps/ArtifactArchiverStepExecution.java:
--------------------------------------------------------------------------------
1 | package org.jenkinsci.plugins.workflow.steps;
2 |
3 | import hudson.FilePath;
4 | import hudson.Launcher;
5 | import hudson.Util;
6 | import hudson.model.Run;
7 | import hudson.model.TaskListener;
8 | import hudson.remoting.VirtualChannel;
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.util.HashMap;
12 | import java.util.Map;
13 | import jenkins.MasterToSlaveFileCallable;
14 | import jenkins.util.BuildListenerAdapter;
15 |
16 | /**
17 | * @author Kohsuke Kawaguchi
18 | */
19 | public class ArtifactArchiverStepExecution extends SynchronousNonBlockingStepExecution {
20 |
21 | private final transient ArtifactArchiverStep step;
22 |
23 | ArtifactArchiverStepExecution(ArtifactArchiverStep step, StepContext context) {
24 | super(context);
25 | this.step = step;
26 | }
27 |
28 | @Override
29 | protected Void run() throws Exception {
30 | FilePath ws = getContext().get(FilePath.class);
31 | ws.mkdirs();
32 | TaskListener listener = getContext().get(TaskListener.class);
33 | if (listener != null) {
34 | listener.getLogger().println(Messages.ArtifactArchiverStepExecution_Deprecated());
35 | }
36 | Map files = ws.act(new ListFiles(step.getIncludes(), step.getExcludes()));
37 | if (files.isEmpty()) {
38 | if (step.getExcludes() != null && !step.getExcludes().equals("")) {
39 | listener.getLogger()
40 | .println(Messages.ArtifactArchiverStepExecution_NoFilesWithExcludes(
41 | step.getIncludes(), step.getExcludes()));
42 | } else {
43 | listener.getLogger().println(Messages.ArtifactArchiverStepExecution_NoFiles(step.getIncludes()));
44 | }
45 | } else {
46 | getContext()
47 | .get(Run.class)
48 | .pickArtifactManager()
49 | .archive(
50 | ws,
51 | getContext().get(Launcher.class),
52 | new BuildListenerAdapter(getContext().get(TaskListener.class)),
53 | files);
54 | }
55 | return null;
56 | }
57 |
58 | private static final class ListFiles extends MasterToSlaveFileCallable