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(core): Add support for an Artifactory Trigger #2728

Merged
merged 2 commits into from
Mar 12, 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
@@ -0,0 +1,37 @@
/*
* Copyright 2019 Pivotal, 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.pipeline.model

import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact

data class ArtifactoryTrigger
@JvmOverloads constructor(
override val type: String = "artifactory",
override val correlationId: String? = null,
override val user: String? = "[anonymous]",
override val parameters: Map<String, Any> = mutableMapOf(),
override val artifacts: List<Artifact> = mutableListOf(),
override val notifications: List<Map<String, Any>> = mutableListOf(),
override var isRebake: Boolean = false,
override var isDryRun: Boolean = false,
override var isStrategy: Boolean = false,
val artifactorySearchName: String
) : Trigger {
override var other: Map<String, Any> = mutableMapOf()
override var resolvedExpectedArtifacts: List<ExpectedArtifact> = mutableListOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ internal class TriggerDeserializer
get("parentExecution").parseValue<Execution>(parser),
get("parentPipelineStageId")?.textValue()
)
looksLikeArtifactory() -> ArtifactoryTrigger(
get("type").textValue(),
get("correlationId")?.textValue(),
get("user")?.textValue() ?: "[anonymous]",
get("parameters")?.mapValue(parser) ?: mutableMapOf(),
get("artifacts")?.listValue(parser) ?: mutableListOf(),
get("notifications")?.listValue(parser) ?: mutableListOf(),
get("rebake")?.booleanValue() == true,
get("dryRun")?.booleanValue() == true,
get("strategy")?.booleanValue() == true,
get("artifactorySearchName").textValue()
)
looksLikeGit() -> GitTrigger(
get("type").textValue(),
get("correlationId")?.textValue(),
Expand Down Expand Up @@ -127,6 +139,9 @@ internal class TriggerDeserializer
private fun JsonNode.looksLikePipeline() =
hasNonNull("parentExecution")

private fun JsonNode.looksLikeArtifactory() =
hasNonNull("artifactorySearchName")

private fun JsonNode.looksLikeCustom() =
customTriggerSuppliers.any { it.predicate.invoke(this) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,31 @@ class TriggerSpec extends Specification {
'''
}

def "can parse an artifactory trigger"() {
given:
def trigger = mapper.readValue(triggerJson, Trigger)

expect:
trigger instanceof ArtifactoryTrigger
with(trigger) {
artifactorySearchName == "search-name"
}

where:
triggerJson = '''
{
"account": "theaccount",
"enabled": true,
"job": "the-job",
"master": "master",
"organization": "org",
"artifactorySearchName": "search-name",
"artifactoryRepository": "libs-demo-local",
"type": "artifactory"
}
'''
}

def pubSubTrigger = '''
{
"attributeConstraints": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class OperationsControllerSpec extends Specification {
trigger : [
type : "manual",
parentPipelineId: "12345",
parentExecution : [name: "abc"]
parentExecution : [name: "abc", type: PIPELINE, id: "1", application: "application"]
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class TaskControllerSpec extends Specification {
application = "covfefe"
stage {
type = "test"
tasks = [new Task(name: 'jobOne'), new Task(name: 'jobTwo')]
tasks = [new Task(id:'1', name: 'jobOne', startTime: 1L, endTime: 2L, implementingClass: 'Class' ),
new Task(id:'2', name: 'jobTwo', startTime: 1L, endTime: 2L, implementingClass: 'Class' )]
}
}])

Expand Down Expand Up @@ -308,6 +309,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-3", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new JenkinsTrigger("master", "job", 1, "test-property-file")
],
[pipelineConfigId: "1", id: "test-4", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local")
]
]

Expand Down Expand Up @@ -335,7 +339,7 @@ class TaskControllerSpec extends Specification {
List results = new ObjectMapper().readValue(response.contentAsString, List)

then:
results.id == ['test-1', 'test-2', 'test-3']
results.id == ['test-1', 'test-2', 'test-3', 'test-4']
}

void '/applications/{application}/pipelines/search should only return pipelines of given types'() {
Expand All @@ -353,6 +357,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-4", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new JenkinsTrigger("master", "job", 1, "test-property-file")
],
[pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local")
]
]

Expand Down Expand Up @@ -399,6 +406,9 @@ class TaskControllerSpec extends Specification {
],
[pipelineConfigId: "1", id: "test-4", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new JenkinsTrigger("master", "job", 1, "test-property-file"), eventId: eventId
],
[pipelineConfigId: "1", id: "test-5", startTime: clock.instant().minus(daysOfExecutionHistory, DAYS).minus(2, HOURS).toEpochMilli(),
trigger: new ArtifactoryTrigger("libs-demo-local"), eventId: wrongEventId
]
]

Expand Down