Skip to content

Commit

Permalink
fix(core): Render templated pipeline params in the pipeline run stage (
Browse files Browse the repository at this point in the history
  • Loading branch information
spinnakerbot authored and louisjimenez committed Jul 16, 2019
1 parent 66249c2 commit 38ca01f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Registry } from 'core/registry';
import { ExecutionDetailsTasks } from '../common';
import { PipelineStageExecutionDetails } from './PipelineStageExecutionDetails';
import { PipelineParametersExecutionDetails } from './PipelineParametersExecutionDetails';
import { PipelineTemplateReader, PipelineTemplateV2Service } from 'core/pipeline';
import { SETTINGS } from 'core/config';

module.exports = angular
.module('spinnaker.core.pipeline.stage.pipelineStage', [])
Expand Down Expand Up @@ -90,45 +92,59 @@ module.exports = angular

if ($scope.stage && $scope.stage.application && pipeline) {
const config = _.find($scope.pipelines, pipeline => pipeline.id === $scope.stage.pipeline);
if (config && config.parameterConfig) {
if (!$scope.stage.pipelineParameters) {
$scope.stage.pipelineParameters = {};
}
$scope.pipelineParameters = config.parameterConfig;
$scope.pipelineParameters.forEach(parameterConfig => {
if (
parameterConfig.default &&
parameterConfig.options &&
!parameterConfig.options.some(option => option.value === parameterConfig.default)
) {
parameterConfig.options.unshift({ value: parameterConfig.default });
}
});
$scope.userSuppliedParameters = $scope.stage.pipelineParameters;

if ($scope.pipelineParameters) {
const acceptedPipelineParams = $scope.pipelineParameters.map(param => param.name);
$scope.invalidParameters = pickBy(
$scope.userSuppliedParameters,
(value, name) => !acceptedPipelineParams.includes(name),
);
}

$scope.hasInvalidParameters = () => Object.keys($scope.invalidParameters || {}).length;
$scope.useDefaultParameters = {};
_.each($scope.pipelineParameters, function(property) {
if (!(property.name in $scope.stage.pipelineParameters) && property.default !== null) {
$scope.useDefaultParameters[property.name] = true;
}
});
if (
SETTINGS.feature.managedPipelineTemplatesV2UI &&
config &&
PipelineTemplateV2Service.isV2PipelineConfig(config)
) {
PipelineTemplateReader.getPipelinePlan(config)
.then(plan => applyPipelineConfigParameters(plan))
.catch(() => clearParams());
} else {
clearParams();
applyPipelineConfigParameters(config);
}
} else {
clearParams();
}
}

function applyPipelineConfigParameters(config) {
if (config && config.parameterConfig) {
if (!$scope.stage.pipelineParameters) {
$scope.stage.pipelineParameters = {};
}
$scope.pipelineParameters = config.parameterConfig;
$scope.pipelineParameters.forEach(parameterConfig => {
if (
parameterConfig.default &&
parameterConfig.options &&
!parameterConfig.options.some(option => option.value === parameterConfig.default)
) {
parameterConfig.options.unshift({ value: parameterConfig.default });
}
});
$scope.userSuppliedParameters = $scope.stage.pipelineParameters;

if ($scope.pipelineParameters) {
const acceptedPipelineParams = $scope.pipelineParameters.map(param => param.name);
$scope.invalidParameters = pickBy(
$scope.userSuppliedParameters,
(value, name) => !acceptedPipelineParams.includes(name),
);
}

$scope.hasInvalidParameters = () => Object.keys($scope.invalidParameters || {}).length;
$scope.useDefaultParameters = {};
_.each($scope.pipelineParameters, function(property) {
if (!(property.name in $scope.stage.pipelineParameters) && property.default !== null) {
$scope.useDefaultParameters[property.name] = true;
}
});
} else {
clearParams();
}
}

function clearParams() {
$scope.pipelineParameters = {};
$scope.useDefaultParameters = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './v2/pipelineTemplateV2.service';
export * from './PipelineTemplateReader';
2 changes: 1 addition & 1 deletion app/scripts/modules/core/src/pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './config/stages/common';
export * from './config/stages/FormikStageConfig';
export * from './config/stages/stageConstants';
export * from './config/stages/templates';
export * from './config/templates/v2/pipelineTemplateV2.service';
export * from './config/templates';
export * from './config/triggers/BaseTrigger';
export * from './config/triggers/RunAsUser';
export * from './config/validation/PipelineConfigValidator';
Expand Down

0 comments on commit 38ca01f

Please sign in to comment.