List of usage examples for com.amazonaws.services.codepipeline.model PipelineContext getStage
public StageContext getStage()
The stage of the pipeline.
From source file:jetbrains.buildServer.codepipeline.CodePipelineBuildListener.java
License:Apache License
private void processJobInput(@NotNull final AgentRunningBuild build) { if (myJobInputProcessed) return;/*from ww w .j a v a 2 s . c o m*/ myJobInputProcessed = true; final Map<String, String> params = build.getSharedConfigParameters(); myJobID = getJobId(params); if (myJobID == null) { LOG.debug(msgForBuild("No AWS CodePipeline job found for the build", build)); return; } AWSCommonParams.withAWSClients(params, new AWSCommonParams.WithAWSClients<Void, RuntimeException>() { @Nullable @Override public Void run(@NotNull AWSClients clients) throws RuntimeException { AWSCodePipelineClient codePipelineClient = null; try { codePipelineClient = clients.createCodePipeLineClient(); final JobData jobData = getJobData(codePipelineClient, params); final PipelineContext pipelineContext = jobData.getPipelineContext(); build.getBuildLogger().message("This build is a part of an AWS CodePipeline pipeline: " + pipelineContext.getPipelineName() + "\nLink: https://console.aws.amazon.com/codepipeline/home?region=" + params.get(AWSCommonParams.REGION_NAME_PARAM) + "#/view/" + pipelineContext.getPipelineName() + "\nStage: " + pipelineContext.getStage().getName() + "\nAction: " + pipelineContext.getAction().getName() + "\nJob ID: " + myJobID); final List<Artifact> inputArtifacts = jobData.getInputArtifacts(); if (inputArtifacts.isEmpty()) { LOG.debug( msgForBuild("No input artifacts provided for the job with ID: " + myJobID, build)); } else { final File inputFolder = new File(params.get(ARTIFACT_INPUT_FOLDER_CONFIG_PARAM)); FileUtil.createDir(inputFolder); final Collection<Download> downloads = S3Util.withTransferManager( getArtifactS3Client(jobData.getArtifactCredentials(), params), new S3Util.WithTransferManager<Download>() { @NotNull @Override public Collection<Download> run(@NotNull final TransferManager manager) throws Throwable { return CollectionsUtil.convertCollection(inputArtifacts, new Converter<Download, Artifact>() { @Override public Download createFrom(@NotNull Artifact artifact) { final S3ArtifactLocation s3Location = artifact.getLocation() .getS3Location(); final File destinationFile = getInputArtifactFile( inputFolder, s3Location.getObjectKey()); build.getBuildLogger() .message("Downloading job input artifact " + s3Location.getObjectKey() + " to " + destinationFile.getAbsolutePath()); return manager.download(s3Location.getBucketName(), s3Location.getObjectKey(), destinationFile); } }); } }); // for backward compatibility, TW-47902 for (Download d : downloads) { makeArtifactCopy(inputFolder, getInputArtifactFile(inputFolder, d.getKey()), d.getKey(), build); } if (!jobData.getOutputArtifacts().isEmpty()) { FileUtil.createDir(new File(params.get(ARTIFACT_OUTPUT_FOLDER_CONFIG_PARAM))); } } } catch (Throwable e) { failOnException(codePipelineClient, build, e); } return null; } }); }