Skip to content

Commit

Permalink
fix(titus): Lookup image form jenkins properties file (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchello2000 committed Jun 1, 2020
1 parent d906fe6 commit 9d4d91f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution;
import com.netflix.spinnaker.orca.api.pipeline.models.Trigger;
import com.netflix.spinnaker.orca.pipeline.model.DockerTrigger;
import com.netflix.spinnaker.orca.pipeline.model.JenkinsTrigger;
import java.util.Map;
import java.util.Optional;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -60,6 +61,10 @@ private Optional<String> getImageId(StageExecution stage) {
if (trigger.getParameters().containsKey("imageName")) {
imageId = (String) trigger.getParameters().get("imageName");
}
if (Strings.isNullOrEmpty(imageId) && trigger instanceof JenkinsTrigger) {
JenkinsTrigger t = (JenkinsTrigger) trigger;
imageId = (String) t.getProperties().getOrDefault("imageName", null);
}
if (Strings.isNullOrEmpty(imageId)) {
imageId = (String) trigger.getOther().get("imageName");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2020 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.orca.clouddriver.tasks.providers.aws

import com.netflix.spinnaker.orca.pipeline.model.JenkinsTrigger
import spock.lang.Specification
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.pipeline
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage

class TitusAmazonServerGroupCreatorDecoratorSpec extends Specification {
def "should find image id from properties file"() {
given:
JenkinsTrigger jenkinsTrigger = new JenkinsTrigger("master", "job", 1, null)
jenkinsTrigger.properties.put("imageName", "imageFromProperties")

def pipeline = pipeline {
trigger = jenkinsTrigger
stage {
type = "deploy"
}
}

def stage = pipeline.stages[0]
TitusAmazonServerGroupCreatorDecorator decorator = new TitusAmazonServerGroupCreatorDecorator()

when:
decorator.modifyCreateServerGroupOperationContext(stage, stage.context)

then:
stage.context.imageId == jenkinsTrigger.properties.get("imageName")

when: 'trigger parameter specified'
stage.context.remove("imageId")
jenkinsTrigger.parameters.put("imageName", "imageFromParameters")
decorator.modifyCreateServerGroupOperationContext(stage, stage.context)

then: 'it takes precedence over props file'
stage.context.imageId == jenkinsTrigger.parameters.get("imageName")
}
}

0 comments on commit 9d4d91f

Please sign in to comment.