Skip to content

Commit

Permalink
fix(artifacts): fix parsing buildInfo when artifacts missing (#2005)
Browse files Browse the repository at this point in the history
  • Loading branch information
asher committed Feb 19, 2018
1 parent db815cb commit fb2f3d5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,17 @@ private static Map<String, Object> findBuildInfoInUpstreamStage(Stage currentSta
.stream()
.filter(it -> {
Map<String, Object> buildInfo = (Map<String, Object>) it.getOutputs().get("buildInfo");
return buildInfo != null && artifactMatch((List<Map<String, String>>) buildInfo.get("artifacts"), packageFilePattern);
return buildInfo != null &&
artifactMatch((List<Map<String, String>>) buildInfo.get("artifacts"), packageFilePattern);
})
.findFirst()
.orElse(null);
return upstreamStage != null ? (Map<String, Object>) upstreamStage.getOutputs().get("buildInfo") : emptyMap();
}

private static boolean artifactMatch(List<Map<String, String>> artifacts, Pattern pattern) {
return artifacts.stream().anyMatch((Map artifact) ->
pattern.matcher(String.valueOf(artifact.get("fileName"))).matches()
);
return artifacts != null &&
artifacts.stream()
.anyMatch((Map artifact) -> pattern.matcher(String.valueOf(artifact.get("fileName"))).matches());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,55 @@ class PackageInfoSpec extends Specification {
targetPkg.packageVersion == null
}

def "findBuildInfoUpstreamStage: finds artifacts when upstream stages have buildInfo w/o artifacts"() {
given:
def pipeline = pipeline {
stage {
refId = "1"
type = "jenkins"
outputs["buildInfo"] = [
url : "http://jenkins",
master : "master",
name : "job",
number : 1,
artifacts: [[fileName: "api_1.1.1-h01.sha123_all.deb", relativePath: "."]],
scm : []
]
}
stage {
refId = "2"
requisiteStageRefIds = ["1"]
context["package"] = "api"
outputs["buildInfo"] = [
url : "http://jenkins",
master : "master",
name : "job",
number : 1,
scm : []
]
}
stage {
type = "bake"
refId = "3"
requisiteStageRefIds = ["2"]
context["package"] = "api"
}
}

def bakeStage = pipeline.stageByRef("3")
PackageType packageType = DEB
ObjectMapper objectMapper = new ObjectMapper()
PackageInfo packageInfo = new PackageInfo(bakeStage, packageType.packageType, packageType.versionDelimiter, true, true, objectMapper)
def pattern = Pattern.compile("api.*")

when:
def buildInfo = packageInfo.findBuildInfoInUpstreamStage(bakeStage, pattern)

then:
noExceptionThrown()
buildInfo.containsKey("artifacts")
}

def "findTargetPackage: stage execution instance of Pipeline with no trigger"() {
given:
def pipeline = pipeline {
Expand Down

0 comments on commit fb2f3d5

Please sign in to comment.