Skip to content

Commit

Permalink
Automate integration tests jenkins job (opensearch-project#1429)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
  • Loading branch information
ohltyler authored and peterzhuamazon committed Feb 16, 2022
1 parent 53a8b9d commit c36b876
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 3 deletions.
112 changes: 112 additions & 0 deletions jenkins/opensearch/integ-test.jenkinsfile
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
}
}
10 changes: 10 additions & 0 deletions src/jenkins/BuildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
7 changes: 7 additions & 0 deletions vars/downloadBuildManifest.groovy
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions vars/runIntegTestScript.groovy
Original file line number Diff line number Diff line change
@@ -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(' '))
}
5 changes: 2 additions & 3 deletions vars/uploadTestResults.groovy
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down

0 comments on commit c36b876

Please sign in to comment.