Example usage for com.amazonaws.services.codepipeline.model Job getId

List of usage examples for com.amazonaws.services.codepipeline.model Job getId

Introduction

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

Prototype


public String getId() 

Source Link

Document

The unique system-generated ID of the job.

Usage

From source file:jetbrains.buildServer.buildTriggers.codepipeline.CodePipelineAsyncPolledBuildTrigger.java

License:Apache License

@Nullable
@Override//  w ww .  jav  a2s .  c  om
public String triggerBuild(@Nullable String previousValue, @NotNull PolledTriggerContext context)
        throws BuildTriggerException {
    final Map<String, String> properties = validateParams(context.getTriggerDescriptor().getProperties());
    try {
        AWSCommonParams.withAWSClients(properties, clients -> {
            final AWSCodePipelineClient codePipelineClient = clients.createCodePipeLineClient();

            final PollForJobsRequest request = new PollForJobsRequest()
                    .withActionTypeId(new ActionTypeId().withCategory(ActionCategory.Build)
                            .withOwner(ActionOwner.Custom).withProvider(TEAMCITY_ACTION_PROVIDER)
                            .withVersion(getActionTypeVersion(codePipelineClient)))
                    .withQueryParam(CollectionsUtil.asMap(ACTION_TOKEN_CONFIG_PROPERTY,
                            CodePipelineUtil.getActionToken(properties)))
                    .withMaxBatchSize(1);

            final List<Job> jobs = codePipelineClient.pollForJobs(request).getJobs();

            if (jobs.size() > 0) {
                if (jobs.size() > 1) {
                    LOG.warn(msgForBt(
                            "Received " + jobs.size()
                                    + ", but only one was expected. Will process only the first job",
                            context.getBuildType()));
                }

                final Job job = jobs.get(0);
                LOG.info(msgForBt(
                        "Received job request with ID: " + job.getId() + " and nonce: " + job.getNonce(),
                        context.getBuildType()));

                try {
                    final AcknowledgeJobRequest acknowledgeJobRequest = new AcknowledgeJobRequest()
                            .withJobId(job.getId()).withNonce(job.getNonce());

                    final String jobStatus = codePipelineClient.acknowledgeJob(acknowledgeJobRequest)
                            .getStatus();
                    if (jobStatus.equals(JobStatus.InProgress.name())) {

                        final BuildCustomizer buildCustomizer = myBuildCustomizerFactory
                                .createBuildCustomizer(context.getBuildType(), null);
                        buildCustomizer.setParameters(getCustomBuildParameters(job, context));

                        final BuildPromotion promotion = buildCustomizer.createPromotion();
                        promotion.addToQueue(TRIGGER_DISPLAY_NAME + " job with ID: " + job.getId());

                        LOG.info(msgForBt(
                                "Acknowledged job with ID: " + job.getId() + " and nonce: " + job.getNonce()
                                        + ", created build promotion " + promotion.getId(),
                                context.getBuildType()));

                    } else {
                        LOG.warn(
                                msgForBt(
                                        "Job ignored with ID: " + job.getId() + " and nonce: " + job.getNonce()
                                                + " because job status is " + jobStatus,
                                        context.getBuildType()));
                    }
                } catch (Throwable e) {
                    final BuildTriggerException buildTriggerException = processThrowable(e);
                    codePipelineClient
                            .putJobFailureResult(new PutJobFailureResultRequest().withJobId(job.getId())
                                    .withFailureDetails(new FailureDetails().withType(FailureType.JobFailed)
                                            .withMessage(buildTriggerException.getMessage())));
                    throw buildTriggerException;
                }
            } else {
                LOG.debug(msgForBt("No jobs found", context.getBuildType()));
            }
            return null;
        });
    } catch (Throwable e) {
        throw processThrowable(e);
    }
    return null;
}

From source file:jetbrains.buildServer.buildTriggers.codepipeline.CodePipelineAsyncPolledBuildTrigger.java

License:Apache License

@NotNull
private Map<String, String> getCustomBuildParameters(@NotNull Job job, @NotNull PolledTriggerContext context) {
    final HashMap<String, String> params = new HashMap<String, String>(
            context.getTriggerDescriptor().getProperties());
    params.put(JOB_ID_CONFIG_PARAM, job.getId());

    params.putIfAbsent(ARTIFACT_INPUT_FOLDER_CONFIG_PARAM, ARTIFACT_INPUT_FOLDER);
    params.putIfAbsent(ARTIFACT_OUTPUT_FOLDER_CONFIG_PARAM, ARTIFACT_OUTPUT_FOLDER);

    return params;
}