Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pipelinetriggers): Support client-provided execution ID for pipeline triggers #563

Merged
merged 2 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}