public boolean perform()

in src/main/java/com/amazonaws/codepipeline/jenkinsplugin/AWSCodePipelinePublisher.java [90:189]


    public boolean perform(
            final AbstractBuild<?,?> action,
            final Launcher launcher,
            final BuildListener listener) {
        final CodePipelineStateModel model = CodePipelineStateService.getModel();

        final boolean actionSucceeded = action.getResult() == Result.SUCCESS;
        boolean awsStatus = actionSucceeded;
        String error = "Failed";

        if (model == null) {
            LoggingHelper.log(listener, "Error with Model Thread Handling");
            return false;
        }

        if (model.isSkipPutJobResult()) {
            LoggingHelper.log(
                    listener,
                    String.format("Skipping PutJobFailureResult call for the job with ID %s", model.getJob().getId()));
            return false;
        }

        final AWSClients awsClients = awsClientFactory.getAwsClient(
                model.getAwsAccessKey(),
                model.getAwsSecretKey(),
                model.getProxyHost(),
                model.getProxyPort(),
                model.getRegion(),
                JenkinsMetadata.getPluginUserAgentPrefix());

        if (!actionSucceeded) {
            if (model.getActionTypeCategory() == CategoryType.Build) {
                error = "Build failed";
            } else if (model.getActionTypeCategory() == CategoryType.Test) {
                error = "Tests failed";
            }
        }

        // This is here if the customer pressed BuildNow, we have nowhere to push
        // or update. But we want to see if we can build what we have.
        if (model.getJob() == null) {
            LoggingHelper.log(listener, "No Job, returning early");
            return actionSucceeded;
        }

        try {
            LoggingHelper.log(listener, "Publishing artifacts");

            final List<Artifact> artifactsFromModel = model.getJob().getData().getOutputArtifacts();

            if (artifactsFromModel.size() != outputArtifacts.size()) {
                throw new IllegalArgumentException(String.format(
                        "The number of output artifacts in the Jenkins project and in the pipeline action do not match. "
                                + "Configure the output locations of your Jenkins project to match the pipeline "
                                + "action's output artifacts. Number of output locations in Jenkins project: %d, "
                                + "number of output artifacts in the pipeline action: %d " + pipelineContextString(model),
                        outputArtifacts.size(),
                        model.getJob().getData().getOutputArtifacts().size()));
            }

            final Set<String> artifactNamesFromModel = getArtifactNamesFromModel(artifactsFromModel);
            final Set<String> artifactNamesFromProject = PublisherCallable.getArtifactNamesFromProject(outputArtifacts);

            if (!artifactNamesFromProject.isEmpty() && !artifactNamesFromProject.equals(artifactNamesFromModel)) {
                throw new IllegalArgumentException(String.format(
                        "Artifact names in the Jenkins project do not match output artifacts in the pipeline action. "
                                + "Either configure the artifact name of each location to match output artifacts for "
                                + "the pipeline action, or leave the field blank. " + pipelineContextString(model)));
            }

            if (!outputArtifacts.isEmpty() && actionSucceeded) {
                callPublish(action, model, listener);
            }
        } catch (final AmazonServiceException ex) {
            error = "Failed to upload output artifact(s): " + ex.getErrorMessage();
            LoggingHelper.log(listener, ex.getMessage());
            LoggingHelper.log(listener, ex);
            awsStatus = false;
        } catch (final RuntimeException | InterruptedException | IOException ex) {
            error = "Failed to upload output artifact(s): " + ex.getMessage();
            LoggingHelper.log(listener, ex.getMessage());
            LoggingHelper.log(listener, ex);
            awsStatus = false;
        } catch (final Throwable ex) {
            error = "Failed to upload output artifact(s): " + ex.getMessage();
            awsStatus = false;
            throw ex;
        } finally {
            PublisherTools.putJobResult(
                    awsStatus,
                    error,
                    action.getId(),
                    model.getJob().getId(),
                    awsClients.getCodePipelineClient(),
                    listener);
            cleanUp(model);
        }

        return awsStatus;
    }