Skip to content

Commit

Permalink
fix(core): Plan templated pipelines before triggering from start tasks (
Browse files Browse the repository at this point in the history
#3039) (#3046)

* fix(core): Plan templated pipelines before triggering from start tasks

spinnaker/spinnaker#4623

* fix(core): Apply Autowired to StartPipelineTask constructor
  • Loading branch information
spinnakerbot authored and louisjimenez committed Jul 19, 2019
1 parent 2ff80ae commit f1ce54f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public static Map<String, Object> planPipeline(

return spelEvaluatedPipeline;
}

public static boolean isV2Pipeline(Map<String, Object> pipelineConfig) {
return pipelineConfig.getOrDefault("type", "").equals("templatedPipeline")
&& pipelineConfig.getOrDefault("schema", "").equals("v2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DependentPipelineExecutionListener implements ExecutionListener {
if (executionPreprocessors) {
// Resolve templated pipelines if enabled.
allPipelines = allPipelines.collect { pipeline ->
if (pipeline.type == 'templatedPipeline' && pipeline?.schema != null && pipeline?.schema != "1") {
if (V2Util.isV2Pipeline(pipeline)) {
return V2Util.planPipeline(contextParameterProcessor, executionPreprocessors, pipeline)
} else {
return pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ package com.netflix.spinnaker.orca.front50.tasks
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.Task
import com.netflix.spinnaker.orca.TaskResult
import com.netflix.spinnaker.orca.extensionpoint.pipeline.ExecutionPreprocessor
import com.netflix.spinnaker.orca.front50.DependentPipelineStarter
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.model.Execution
import com.netflix.spinnaker.orca.pipeline.model.Stage
import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor
import com.netflix.spinnaker.orca.pipelinetemplate.V2Util
import com.netflix.spinnaker.security.AuthenticatedRequest
import com.netflix.spinnaker.security.User
import groovy.util.logging.Slf4j
Expand All @@ -33,11 +36,21 @@ import org.springframework.stereotype.Component
@Slf4j
class StartPipelineTask implements Task {

@Autowired(required = false)
Front50Service front50Service
private final Front50Service front50Service

private final DependentPipelineStarter dependentPipelineStarter

private final ContextParameterProcessor contextParameterProcessor

private final List<ExecutionPreprocessor> executionPreprocessors

@Autowired
DependentPipelineStarter dependentPipelineStarter
StartPipelineTask(Optional<Front50Service> front50Service, DependentPipelineStarter dependentPipelineStarter, ContextParameterProcessor contextParameterProcessor, Optional<List<ExecutionPreprocessor>> executionPreprocessors) {
this.front50Service = front50Service.orElse(null)
this.dependentPipelineStarter = dependentPipelineStarter
this.contextParameterProcessor = contextParameterProcessor
this.executionPreprocessors = executionPreprocessors.orElse(Collections.emptyList())
}

@Override
TaskResult execute(Stage stage) {
Expand All @@ -60,6 +73,10 @@ class StartPipelineTask implements Task {
throw new IllegalArgumentException("The referenced ${isStrategy ? 'custom strategy' : 'pipeline'} is disabled")
}

if (V2Util.isV2Pipeline(pipelineConfig)) {
pipelineConfig = V2Util.planPipeline(contextParameterProcessor, executionPreprocessors, pipelineConfig)
}

def parameters = stage.context.pipelineParameters ?: [:]

if (isStrategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package com.netflix.spinnaker.orca.front50.tasks

import com.netflix.spinnaker.orca.extensionpoint.pipeline.ExecutionPreprocessor
import com.netflix.spinnaker.orca.front50.DependentPipelineStarter
import com.netflix.spinnaker.orca.front50.Front50Service
import com.netflix.spinnaker.orca.pipeline.model.Execution
import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor
import com.netflix.spinnaker.security.User
import spock.lang.Specification
import spock.lang.Subject
Expand All @@ -31,9 +33,11 @@ class StartPipelineTaskSpec extends Specification {

Front50Service front50Service = Mock(Front50Service)
DependentPipelineStarter dependentPipelineStarter = Stub(DependentPipelineStarter)
ContextParameterProcessor contextParameterProcessor = new ContextParameterProcessor()
List<ExecutionPreprocessor> executionPreprocessors

@Subject
StartPipelineTask task = new StartPipelineTask(front50Service: front50Service,
dependentPipelineStarter: dependentPipelineStarter)
StartPipelineTask task = new StartPipelineTask(Optional.of(front50Service), dependentPipelineStarter, contextParameterProcessor, Optional.ofNullable(executionPreprocessors))

@Unroll
def "should trigger the dependent pipeline with the correct context and parentPipelineStageId"() {
Expand Down

0 comments on commit f1ce54f

Please sign in to comment.