Example usage for com.amazonaws.services.codepipeline.model JobData getEncryptionKey

List of usage examples for com.amazonaws.services.codepipeline.model JobData getEncryptionKey

Introduction

In this page you can find the example usage for com.amazonaws.services.codepipeline.model JobData getEncryptionKey.

Prototype


public EncryptionKey getEncryptionKey() 

Source Link

Document

Represents information about the key used to encrypt data in the artifact store, such as an AWS Key Management Service (AWS KMS) key.

Usage

From source file:jetbrains.buildServer.codepipeline.CodePipelineBuildListener.java

License:Apache License

private void processJobOutput(@NotNull final AgentRunningBuild build,
        @NotNull final BuildFinishedStatus buildStatus) {
    if (myJobID == null)
        return;//w  w w.ja  v a 2 s.c o m

    AWSCommonParams.withAWSClients(build.getSharedConfigParameters(),
            new AWSCommonParams.WithAWSClients<Void, RuntimeException>() {
                @Nullable
                @Override
                public Void run(@NotNull AWSClients clients) throws RuntimeException {
                    AWSCodePipelineClient codePipelineClient = null;
                    try {
                        codePipelineClient = clients.createCodePipeLineClient();
                        if (build.isBuildFailingOnServer()) {
                            publishJobFailure(codePipelineClient, build, "Build failed");
                        } else if (BuildFinishedStatus.INTERRUPTED == buildStatus) {
                            publishJobFailure(codePipelineClient, build, "Build interrupted");
                        } else {
                            final Map<String, String> params = build.getSharedConfigParameters();
                            final JobData jobData = getJobData(codePipelineClient, params);

                            final List<Artifact> outputArtifacts = jobData.getOutputArtifacts();
                            if (outputArtifacts.isEmpty()) {
                                LOG.debug(msgForBuild(
                                        "No output artifacts expected for the job with ID: " + myJobID, build));
                            } else {
                                final File artifactOutputFolder = new File(
                                        params.get(ARTIFACT_OUTPUT_FOLDER_CONFIG_PARAM));

                                S3Util.withTransferManager(
                                        getArtifactS3Client(jobData.getArtifactCredentials(), params),
                                        new S3Util.WithTransferManager<Upload>() {
                                            @NotNull
                                            @Override
                                            public Collection<Upload> run(
                                                    @NotNull final TransferManager manager) throws Throwable {
                                                return CollectionsUtil.convertCollection(outputArtifacts,
                                                        new Converter<Upload, Artifact>() {
                                                            @Override
                                                            public Upload createFrom(
                                                                    @NotNull Artifact artifact) {
                                                                final File buildArtifact = getBuildArtifact(
                                                                        artifact,
                                                                        jobData.getPipelineContext()
                                                                                .getPipelineName(),
                                                                        artifactOutputFolder, build);
                                                                final S3ArtifactLocation s3Location = artifact
                                                                        .getLocation().getS3Location();

                                                                build.getBuildLogger().message(
                                                                        "Uploading job output artifact "
                                                                                + s3Location.getObjectKey()
                                                                                + " from " + buildArtifact
                                                                                        .getAbsolutePath());
                                                                return manager.upload(new PutObjectRequest(
                                                                        s3Location.getBucketName(),
                                                                        s3Location.getObjectKey(),
                                                                        buildArtifact)
                                                                                .withSSEAwsKeyManagementParams(
                                                                                        getSSEAwsKeyManagementParams(
                                                                                                jobData.getEncryptionKey())));
                                                            }
                                                        });
                                            }
                                        });

                                publishJobSuccess(codePipelineClient, build);
                            }
                        }
                    } catch (Throwable e) {
                        failOnException(codePipelineClient, build, e);
                    }
                    return null;
                }
            });
}