Skip to content

Commit

Permalink
[Dashboards] check BuildManifest has artifacts (opensearch-project#1568)
Browse files Browse the repository at this point in the history
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:
opensearch-project#1565

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla authored Jan 30, 2022
1 parent 1c75e01 commit 0123319
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jenkins/BuildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<>()
}

}
Expand Down
5 changes: 5 additions & 0 deletions tests/jenkins/TestBuildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
31 changes: 31 additions & 0 deletions tests/jenkins/jobs/BuildManifest_Jenkinsfile_component_no_artifact
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0123319

Please sign in to comment.