diff --git a/jenkins/opensearch/integ-test.jenkinsfile b/jenkins/opensearch/integ-test.jenkinsfile new file mode 100644 index 0000000000..e4a8c0a059 --- /dev/null +++ b/jenkins/opensearch/integ-test.jenkinsfile @@ -0,0 +1,112 @@ +lib = library(identifier: "jenkins@20211118", retriever: legacySCM(scm)) + +pipeline { + agent none + environment { + AWS_ROLE_ARN = "arn:aws:iam::${AWS_ACCOUNT_PUBLIC}:role/opensearch-test" + AWS_ROLE_SESSION_NAME = "jenkins-test-session" + BUILD_MANIFEST= "build-manifest.yml" + } + tools { + jdk "JDK14" + maven "maven-3.8.2" + } + parameters { + string( + defaultValue: '', + name: 'TEST_MANIFEST', + description: 'Test manifest under the manifests folder, e.g. manifests/2.0.0/opensearch-2.0.0-test.yml.', + trim: true + ) + string( + defaultValue: '', + name: 'BUILD_MANIFEST_URL', + description: 'The build manifest URL, e.g. https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.2.2/98/linux/x64/builds/opensearch/manifest.yml.', + trim: true + ) + string( + defaultValue: '', + name: 'AGENT_LABEL', + description: 'The agent label where the tests should be executed, e.g. Jenkins-Agent-al2-x64-c54xlarge-Docker-Host.', + trim: true + ) + } + stages { + stage('integ-test') { + agent { + node { + label "${AGENT_LABEL}" + } + } + steps { + script { + def buildManifestObj = downloadBuildManifest( + url: BUILD_MANIFEST_URL, + path: BUILD_MANIFEST + ) + String buildId = buildManifestObj.getArtifactBuildId() + env.BUILD_ID = buildId + echo "BUILD_MANIFEST: ${BUILD_MANIFEST}" + echo "BUILD_ID: ${BUILD_ID}" + + runIntegTestScript( + buildManifest: "${BUILD_MANIFEST}", + testManifest: "${TEST_MANIFEST}", + buildId: "${BUILD_ID}" + ) + } + } + post { + always { + script { + uploadTestResults( + buildManifestFileName: "${BUILD_MANIFEST}", + jobName: 'integ-test', + buildNumber: "${BUILD_ID}" + ) + } + cleanWs disableDeferredWipeout: true, deleteDirs: true + } + } + } + } + + post { + success { + node('Jenkins-Agent-al2-x64-m5xlarge') { + script { + def stashed = lib.jenkins.Messages.new(this).get(['integ-test']) + publishNotification( + icon: ':white_check_mark:', + message: 'Integration Tests Successful', + extra: stashed, + credentialsId: 'INTEG_TEST_WEBHOOK', + ) + + cleanWs( + disableDeferredWipeout: true, + deleteDirs: true + ) + } + } + } + failure { + node('Jenkins-Agent-al2-x64-m5xlarge') { + script { + def stashed = lib.jenkins.Messages.new(this).get(['integ-test']) + publishNotification( + icon: ':warning:', + message: 'Failed Integration Tests', + extra: stashed, + credentialsId: 'INTEG_TEST_WEBHOOK', + ) + + cleanWs( + disableDeferredWipeout: true, + deleteDirs: true + ) + } + } + } + } +} diff --git a/src/jenkins/BuildManifest.groovy b/src/jenkins/BuildManifest.groovy index b533a79f0b..4f4038a4d9 100644 --- a/src/jenkins/BuildManifest.groovy +++ b/src/jenkins/BuildManifest.groovy @@ -10,12 +10,14 @@ package jenkins class BuildManifest implements Serializable { class Build implements Serializable { + String id String name String version String platform String architecture Build(Map data) { + this.id = data.id this.name = data.name this.version = data.version this.platform = data.platform @@ -90,6 +92,14 @@ class BuildManifest implements Serializable { ].join('/') } + public String getArtifactArchitecture() { + return this.build.architecture + } + + public String getArtifactBuildId() { + return this.build.id + } + public String getMinArtifact() { components.get(build.name.replace(' ','-'))?.artifacts?.get("dist")?.first() } diff --git a/vars/downloadBuildManifest.groovy b/vars/downloadBuildManifest.groovy new file mode 100644 index 0000000000..c83a72e169 --- /dev/null +++ b/vars/downloadBuildManifest.groovy @@ -0,0 +1,7 @@ +def call(Map args = [:]) { + def lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm)) + + sh "wget ${args.url} -O ${args.path}" + def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: args.path)) + return buildManifestObj +} \ No newline at end of file diff --git a/vars/runIntegTestScript.groovy b/vars/runIntegTestScript.groovy new file mode 100644 index 0000000000..2137a989ec --- /dev/null +++ b/vars/runIntegTestScript.groovy @@ -0,0 +1,14 @@ +void call(Map args = [:]) { + String jobName = args.jobName ?: 'distribution-build-opensearch' + lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm)) + def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: args.buildManifest)) + String artifactRootUrl = buildManifest.getArtifactRootUrl(jobName, args.buildId) + echo "Artifact root URL: ${artifactRootUrl}" + + sh([ + './test.sh', + 'integ-test', + "${args.testManifest}", + "--paths opensearch=${artifactRootUrl}", + ].join(' ')) +} \ No newline at end of file diff --git a/vars/uploadTestResults.groovy b/vars/uploadTestResults.groovy index f4f1cae313..399ce34a1d 100644 --- a/vars/uploadTestResults.groovy +++ b/vars/uploadTestResults.groovy @@ -1,8 +1,7 @@ void call(Map args = [:]) { def lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm)) - - def manifestFilename = args.manifest ?: "manifest.yml" - def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: manifestFilename)) + + def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: args.buildManifestFileName)) def artifactPath = buildManifest.getArtifactRoot(args.jobName, args.buildNumber) echo "Uploading to s3://${ARTIFACT_BUCKET_NAME}/${artifactPath}"