diff --git a/build.gradle b/build.gradle index 3257afe5b..3ec17a80e 100644 --- a/build.gradle +++ b/build.gradle @@ -121,7 +121,7 @@ jacocoTestReport { } } -String version = '6.3.1' +String version = '6.3.2' task updateVersion { doLast { diff --git a/tests/jenkins/TestValidateArtifacts.groovy b/tests/jenkins/TestValidateArtifacts.groovy index 62563bcbf..d53f698a9 100644 --- a/tests/jenkins/TestValidateArtifacts.groovy +++ b/tests/jenkins/TestValidateArtifacts.groovy @@ -19,7 +19,7 @@ class TestValidateArtifacts extends BuildPipelineTest { @Before void setUp() { - this.registerLibTester(new ValidateArtifactsLibTester('1.0.0', 'foo')) + this.registerLibTester(new ValidateArtifactsLibTester('1.0.0', 'tar', 'x64', 'linux', 'opensearch')) super.setUp() } @@ -28,16 +28,4 @@ class TestValidateArtifacts extends BuildPipelineTest { void validateArtifacts() { super.testPipeline('tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile') } - - @Test - void checkScriptcall(){ - runScript('tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile') - def shcommand = helper.callStack.findAll { call -> - call.methodName == 'sh' - }.collect { call -> - callArgsToString(call) - } - assertThat(shcommand.size(), equalTo(1)) - assertThat(shcommand, hasItem('/tmp/workspace/validation.sh --version 1.0.0 --project foo')) - } } diff --git a/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile b/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile index 8e1eefb72..04a736465 100644 --- a/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile +++ b/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile @@ -15,7 +15,10 @@ pipeline { script { validateArtifacts( version: '1.0.0', - project: 'foo' + distribution: 'tar', + arch: 'x64', + platform: 'linux', + projects: 'opensearch' ) } } diff --git a/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile.txt b/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile.txt index 2e715e19b..661c16909 100644 --- a/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile.txt +++ b/tests/jenkins/jobs/ValidateArtifacts_Jenkinsfile.txt @@ -3,6 +3,6 @@ ValidateArtifacts_Jenkinsfile.echo(Executing on agent [label:none]) ValidateArtifacts_Jenkinsfile.stage(validate, groovy.lang.Closure) ValidateArtifacts_Jenkinsfile.script(groovy.lang.Closure) - ValidateArtifacts_Jenkinsfile.validateArtifacts({version=1.0.0, project=foo}) + ValidateArtifacts_Jenkinsfile.validateArtifacts({version=1.0.0, distribution=tar, arch=x64, platform=linux, projects=opensearch}) validateArtifacts.fileExists(/tmp/workspace/validation.sh) - validateArtifacts.sh(/tmp/workspace/validation.sh --version 1.0.0 --project foo) + validateArtifacts.sh(./validation.sh --version 1.0.0 --distribution tar --platform linux --arch x64 --projects opensearch) diff --git a/tests/jenkins/lib-testers/ValidateArtifactsLibTester.groovy b/tests/jenkins/lib-testers/ValidateArtifactsLibTester.groovy index b943bed2f..f6eeb7d4a 100644 --- a/tests/jenkins/lib-testers/ValidateArtifactsLibTester.groovy +++ b/tests/jenkins/lib-testers/ValidateArtifactsLibTester.groovy @@ -12,11 +12,18 @@ import static org.hamcrest.MatcherAssert.assertThat class ValidateArtifactsLibTester extends LibFunctionTester { private String version - private String project + private String distribution + private String arch + private String platform + private String projects - public ValidateArtifactsLibTester(version, project) { + public ValidateArtifactsLibTester(version, distribution, arch, platform, projects) { this.version = version - this.project = project + this.distribution = distribution + this.arch = arch + this.platform = platform + this.projects = projects + } void configure(helper, binding) { @@ -25,12 +32,12 @@ class ValidateArtifactsLibTester extends LibFunctionTester { void parameterInvariantsAssertions(call) { assertThat(call.args.version.first(), notNullValue()) - assertThat(call.args.project.first(), notNullValue()) + assertThat(call.args.projects.first(), notNullValue()) } boolean expectedParametersMatcher(call) { return call.args.version.first().toString().equals(this.version) - && call.args.project.first().toString().equals(this.project) + && call.args.projects.first().toString().equals(this.projects) } String libFunctionName() { diff --git a/vars/validateArtifacts.groovy b/vars/validateArtifacts.groovy index 7076fcbc2..652d1c391 100644 --- a/vars/validateArtifacts.groovy +++ b/vars/validateArtifacts.groovy @@ -9,20 +9,41 @@ /** Wrapper that runs validation.sh script with provided args. -@param Map[] - Any arguments that you want to be passed to validation.sh script. eg: version: 1.0.0 will be passed as --version 1.0.0 +[ +@param Map[version] - Version of the opensearch artifact that needs to be validated. +@param Map[file_path] - Url paths to Opensearch or OpenSearch DashBoards artifacts. +Note: These parameters are mutually exclusive. Provide either of 'version' or 'file_path' parameters, to proceed with the validation. +] +@param Map[distribution] - Choose distribution type among [tar(default),rpm,yum,docker]. +@param Map[architecture] - Select the architecture type among [x64(default) and arm64]. +@param Map[platform] - The distribution platform. +@param Map[projects] - Specify the project type OpenSearch or Both(OpenSearch and OpenSearch-DashBoards). +@param Map[docker_source] - Specify the docker source from [DockerHub(default), ECR] to pull the docker image. +@param Map[os_build_number] - Specify Opensearch build number from opensearchstaging if required. +@param Map[osd_build_number] - Specify Opensearch-Dashboard build number from opensearchstaging if required. +@param Map[artifact_type] - Select the artifact type among [staging and production]. +@param Map[allow_http] - Supports validation of artifacts in which security plugin is absent.architecture. +@param Map[docker_args] - Select either of [using-staging-artifact-only', 'validate-digest-only] for docker validation. */ void call(Map args = [:]) { if (!fileExists("$WORKSPACE/validation.sh")) { println("Validation.sh script not found in the workspace: ${WORKSPACE}, exit 1") System.exit(1) } - String arguments = generateArguments(args) - sh "${WORKSPACE}/validation.sh ${arguments}" -} -String generateArguments(args) { - String arguments = '' - // generate of command line arguments - args.each { key, value -> arguments += " --${key } ${value }" } - return arguments + sh([ + './validation.sh', + args.version ? "--version ${args.version}" : "", + args.file_path ? "--file-path ${args.file_path}" : "", + args.distribution ? "--distribution ${args.distribution}" : "", + args.platform ? "--platform ${args.platform}" : "", + args.arch ? "--arch ${args.arch}" : "", + args.projects ? "--projects ${args.projects}" : "", + args.docker_source ? "--docker-source ${args.docker_source}" : "", + args.os_build_number ? "--os-build-number ${args.os_build_number}" : "", + args.osd_build_number ? "--osd-build-number ${args.osd_build_number}" : "", + args.artifact_type ? "--artifact-type ${args.artifact_type}" : "", + args.allow_http ? '--allow-http' : "", + args.docker_args ? "--${args.docker_args}" : "", + ].join(' ').trim()) }