From 0123319f7fdf5bc25428c562d857a4779cb5cc05 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Sun, 30 Jan 2022 12:58:14 -0800 Subject: [PATCH] [Dashboards] check BuildManifest has artifacts (#1568) Verifies if the build manifest has artifacts or not before using the value. This allows for components that don't produce build artifacts to be passed to the groovy class without failing. Issue resolved: https://github.com/opensearch-project/opensearch-build/issues/1565 Signed-off-by: Kawika Avilla --- src/jenkins/BuildManifest.groovy | 2 +- tests/jenkins/TestBuildManifest.groovy | 5 +++ ...Manifest_Jenkinsfile_component_no_artifact | 31 +++++++++++++++++++ ...fest_Jenkinsfile_component_no_artifact.txt | 20 ++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact create mode 100755 tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact.txt diff --git a/src/jenkins/BuildManifest.groovy b/src/jenkins/BuildManifest.groovy index 4f4038a4d9..d73ccbad9b 100644 --- a/src/jenkins/BuildManifest.groovy +++ b/src/jenkins/BuildManifest.groovy @@ -62,7 +62,7 @@ class BuildManifest implements Serializable { this.ref = data.ref this.commit_id = data.commit_id this.repository = data.repository - this.artifacts = new HashMap<>(data.artifacts) + this.artifacts = data.artifacts ? new HashMap<>(data.artifacts) : new HashMap<>() } } diff --git a/tests/jenkins/TestBuildManifest.groovy b/tests/jenkins/TestBuildManifest.groovy index 3666f3686c..74d2155ab5 100644 --- a/tests/jenkins/TestBuildManifest.groovy +++ b/tests/jenkins/TestBuildManifest.groovy @@ -15,4 +15,9 @@ class TestBuildManifest extends BuildPipelineTest { void testBuildManifest() { super.testPipeline("tests/jenkins/jobs/BuildManifest_Jenkinsfile") } + + @Test + void testBuildManifestWithComponentWithNoArtifact() { + super.testPipeline("tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact") + } } diff --git a/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact b/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact new file mode 100644 index 0000000000..1d13890275 --- /dev/null +++ b/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +def lib = library("jenkins") + +pipeline { + agent none + stages { + stage('Build Manifest Properties') { + steps { + script { + def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: "tests/data/opensearch-dashboards-build-1.2.0.yml")) + echo buildManifest.build.name + echo buildManifest.build.version + echo buildManifest.build.platform + echo buildManifest.build.architecture + echo buildManifest.build.getFilename() + echo buildManifest.getArtifactRoot('bundle-build', '1') + echo buildManifest.getArtifactRootUrl('https://ci.opensearch.org/ci/dbc', 'bundle-build', '1') + echo buildManifest.build.getPackageName() + echo buildManifest.components.getMinArtifact() + } + } + } + } +} diff --git a/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact.txt b/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact.txt new file mode 100755 index 0000000000..6a82b536d1 --- /dev/null +++ b/tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact.txt @@ -0,0 +1,20 @@ + BuildManifest_Jenkinsfile_component_no_artifact.run() + BuildManifest_Jenkinsfile_component_no_artifact.library(jenkins) + BuildManifest_Jenkinsfile_component_no_artifact.pipeline(groovy.lang.Closure) + BuildManifest_Jenkinsfile_component_no_artifact.echo(Executing on agent [label:none]) + BuildManifest_Jenkinsfile_component_no_artifact.stage(Build Manifest Properties, groovy.lang.Closure) + BuildManifest_Jenkinsfile_component_no_artifact.script(groovy.lang.Closure) + BuildManifest_Jenkinsfile_component_no_artifact.readYaml({file=tests/data/opensearch-dashboards-build-1.2.0.yml}) + BuildManifest.asBoolean() + BuildManifest_Jenkinsfile_component_no_artifact.echo(OpenSearch Dashboards) + BuildManifest_Jenkinsfile_component_no_artifact.echo(1.2.0) + BuildManifest_Jenkinsfile_component_no_artifact.echo(linux) + BuildManifest_Jenkinsfile_component_no_artifact.echo(x64) + BuildManifest_Jenkinsfile_component_no_artifact.echo(opensearch-dashboards) + BuildManifest.getArtifactRoot(bundle-build, 1) + BuildManifest_Jenkinsfile_component_no_artifact.echo(bundle-build/1.2.0/1/linux/x64) + BuildManifest.getArtifactRootUrl(https://ci.opensearch.org/ci/dbc, bundle-build, 1) + BuildManifest_Jenkinsfile_component_no_artifact.echo(https://ci.opensearch.org/ci/dbc/bundle-build/1.2.0/1/linux/x64) + BuildManifest_Jenkinsfile_component_no_artifact.echo(opensearch-dashboards-1.2.0-linux-x64.tar.gz) + BuildManifest.getMinArtifact() + BuildManifest_Jenkinsfile_component_no_artifact.echo(dist/opensearch-dashboards-min-1.2.0-linux-x64.tar.gz)