Skip to content

Commit

Permalink
feat(get_commits): Display SCM changes in pipeline-triggered pipelines
Browse files Browse the repository at this point in the history
The changes tab that displays SCM diff between deploys was not showing if the pipeline was triggered by another pipeline. Now it does.
  • Loading branch information
jervi committed Oct 9, 2017
1 parent d7b7396 commit 375d7f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class GetCommitsTask implements DiffTask {

//figure out the new asg/ami/commit
String targetAmi = getTargetAmi(stage.context, region)
if (!targetAmi) {
def parentPipeline = stage.execution.trigger?.parentExecution
while (!targetAmi && parentPipeline?.context) {
targetAmi = getTargetAmi(parentPipeline.context, region)
parentPipeline = parentPipeline.trigger?.parentExecution
}
}

//get commits from igor
sourceInfo = resolveInfoFromAmi(ancestorAmi, account, region)
Expand Down Expand Up @@ -203,7 +210,7 @@ class GetCommitsTask implements DiffTask {
def globalAccount = front50Service.credentials.find { it.global }
def applicationAccount = globalAccount?.name ?: account
Application app = front50Service.get(application)
return [repoType : app?.details().repoType, projectKey : app?.details().repoProjectKey, repositorySlug : app?.details().repoSlug]
return [repoType : app?.details()?.repoType, projectKey : app?.details()?.repoProjectKey, repositorySlug : app?.details()?.repoSlug]
}

String getBuildFromAppVersion(String appVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class GetCommitsTaskSpec extends Specification {
jobState = 'SUCCESS'
}

Stage<Pipeline> setupGetCommits(Map contextMap, String account, String app, String sourceImage, String targetImage, String region, String cluster, String serverGroup, int serverGroupCalls = 1, int oortCalls = 1) {
Stage<Pipeline> setupGetCommits(Map contextMap, String account, String app, String sourceImage, String targetImage, String region, String cluster, String serverGroup, int serverGroupCalls = 1, int oortCalls = 1, Pipeline pipeline = this.pipeline) {
def stage = new Stage<>(pipeline, "stash", contextMap)

task.buildService = Stub(BuildService) {
Expand Down Expand Up @@ -629,4 +629,46 @@ class GetCommitsTaskSpec extends Specification {
ancestorBuild | targetBuild
"216" | "217"
}

@Unroll
def "get commits from parent pipelines"() {
given:
Pipeline parentPipeline = new Pipeline("parentPipeline")
Pipeline childPipeline = new Pipeline("childPipeline")
String katoTasks = "[{\"resultObjects\": [" +
"{\"ancestorServerGroupNameByRegion\": { \"${region}\":\"${serverGroup}\"}}," +
"{\"messages\" : [ ], \"serverGroupNameByRegion\": {\"${region}\": \"${targetServerGroup}\"},\"serverGroupNames\": [\"${region}:${targetServerGroup}\"]}],\"status\": {\"completed\": true,\"failed\": false}}]"
def katoMap = getObjectMapper().readValue(katoTasks, List)
def contextMap = [application: app, account: account,
source : [asgName: serverGroup, region: region, account: account], "deploy.server.groups": ["us-west-1": [targetServerGroup]], "kato.tasks" : katoMap]

parentPipeline.context = [deploymentDetails: [[imageId: "ami-foo", ami: "amiFooName", region: "us-east-1"], [imageId: targetImage, ami: targetImageName, region: region]]]
Stage<Pipeline> parentStage = setupGetCommits(contextMap, account, app, sourceImage, targetImage, region, cluster, serverGroup, 1, 1, parentPipeline)
Stage<Pipeline> childStage = new Stage<>(childPipeline, "stash", [application: app, account: account, source: [asgName: serverGroup, region: region, account: account], "deploy.server.groups": ["us-west-1": [targetServerGroup]], "kato.tasks" : katoMap])

parentPipeline.stages << parentStage
childStage.execution.trigger.put("parentPipelineId", parentStage.execution.id)
childStage.execution.trigger.put("parentExecution", parentStage.execution)

when:
def result = task.execute(childStage)

then:
assertResults(result, ExecutionStatus.SUCCEEDED)

where:
app = "myapp"
account = "test"
region = "us-west-1"
sourceImage = "ami-source"
targetImage = "ami-target"
targetImageName = "amiTargetName"
jobState = 'SUCCESS'

cluster | serverGroup | targetServerGroup
"myapp" | "myapp" | "myapp-v000"
"myapp" | "myapp-v001" | "myapp-v002"
"myapp-stack" | "myapp-stack-v002" | "myapp-stack-v003"
"myapp-stack-detail" | "myapp-stack-detail-v002" | "myapp-stack-detail-v003"
}
}

0 comments on commit 375d7f1

Please sign in to comment.