Skip to content

Commit

Permalink
feat(pipelinetriggers): Support client-provided execution ID for pipe…
Browse files Browse the repository at this point in the history
…line triggers (#563)
  • Loading branch information
robzienert committed May 30, 2019
1 parent d845cea commit 471a5d4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact;
import java.util.List;
import java.util.Map;
import lombok.*;
import lombok.Builder;
import lombok.NonNull;
import lombok.ToString;
import lombok.Value;
import lombok.experimental.Wither;

@JsonDeserialize(builder = Pipeline.PipelineBuilder.class)
Expand All @@ -42,6 +45,8 @@ public class Pipeline {

@JsonProperty String id;

@JsonProperty String executionId;

@JsonProperty String executionEngine;

@JsonProperty boolean parallel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
"link",
"linkText",
"application",
"pipeline"
"pipeline",
"correlationId",
"executionId"
},
includeFieldNames = false)
@Value
Expand Down Expand Up @@ -106,6 +108,8 @@ public String toString() {
// Configuration for pipeline triggers
String application;
String pipeline;
String correlationId;
String executionId;

// Configuration for git triggers
String project;
Expand Down Expand Up @@ -226,6 +230,14 @@ public Trigger atEventId(final String eventId) {
return this.toBuilder().eventId(eventId).build();
}

public Trigger atCorrelationId(final String correlationId) {
return this.toBuilder().correlationId(correlationId).build();
}

public Trigger atExecutionId(final String executionId) {
return this.toBuilder().executionId(executionId).build();
}

public Trigger atNotifications(final List<Map<String, Object>> notifications) {
return this.toBuilder().notifications(notifications).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.spinnaker.echo.pipelinetriggers.postprocessors;

import com.google.common.base.Strings;
import com.netflix.spinnaker.echo.model.Pipeline;
import com.netflix.spinnaker.echo.model.Trigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/** Automatically sets a pipeline's execution ID if one was supplied by the eventing trigger. */
@Component
public class ProvidedExecutionIdPipelinePostProcessor implements PipelinePostProcessor {

private final Logger log =
LoggerFactory.getLogger(ProvidedExecutionIdPipelinePostProcessor.class);

@Override
public Pipeline processPipeline(Pipeline inputPipeline) {
Trigger trigger = inputPipeline.getTrigger();
if (!Strings.isNullOrEmpty(trigger.getExecutionId())) {
log.debug(
"Assigning trigger-provided execution ID to pipeline: '{}'", trigger.getExecutionId());
return inputPipeline.withExecutionId(trigger.getExecutionId());
}
return inputPipeline;
}
}

0 comments on commit 471a5d4

Please sign in to comment.