Skip to content

Commit

Permalink
Update uploadTestResults lib env vars with credentials
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya committed Jun 23, 2022
1 parent 570a8ce commit d36e73f
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/jenkins/TestCCRPerfTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TestCCRPerfTest extends BuildPipelineTest {
}
assertThat(resultUploadScriptCommands.size(), equalTo(1))
assertThat(resultUploadScriptCommands, hasItem(
"{file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
"{file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/TestRunNonSecurityPerfTestScript.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TestRunNonSecurityPerfTestScript extends BuildPipelineTest {
}
assertThat(resultUploadScriptCommands.size(), equalTo(1))
assertThat(resultUploadScriptCommands, hasItem(
"{file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
"{file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/TestRunPerfTestScript.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TestRunPerfTestScript extends BuildPipelineTest {
}
assertThat(resultUploadScriptCommands.size(), equalTo(2))
assertThat(resultUploadScriptCommands, hasItem(
"{file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
"{file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results}".toString()
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ CCR Performance tests for 1236 completed})
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 1236)
BuildManifest.getArtifactRoot(perf-test, 1236)
uploadTestResults.echo(Uploading to s3://test_bucket/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=dummy_account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(test://artifact.url, perf-test, 1236)
Messages.asBoolean()
Messages.add(test_stage, test://artifact.url/perf-test/1.3.0/1236/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 215)
BuildManifest.getArtifactRoot(dummy_job, 215)
uploadTestResults.echo(Uploading to s3://DUMMY_ARTIFACT_BUCKET_NAME/dummy_job/1.2.0/215/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=DUMMY_AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=DUMMY_ARTIFACT_BUCKET_NAME, path=dummy_job/1.2.0/215/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/dummy_job/1.2.0/215/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=dummy_job/1.2.0/215/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(DUMMY_PUBLIC_ARTIFACT_URL, dummy_job, 215)
Messages.asBoolean()
Messages.add(DUMMY_STAGE_NAME, DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/1.2.0/215/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 215)
BuildManifest.getArtifactRoot(dummy_job, 215)
uploadTestResults.echo(Uploading to s3://DUMMY_ARTIFACT_BUCKET_NAME/dummy_job/1.2.0/215/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=DUMMY_AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=DUMMY_ARTIFACT_BUCKET_NAME, path=dummy_job/1.2.0/215/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/dummy_job/1.2.0/215/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=dummy_job/1.2.0/215/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(DUMMY_PUBLIC_ARTIFACT_URL, dummy_job, null)
Messages.asBoolean()
Messages.add(DUMMY_STAGE_NAME, DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/1.2.0/null/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 717)
BuildManifest.getArtifactRoot(dummy_job, 717)
uploadTestResults.echo(Uploading to s3://DUMMY_ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=DUMMY_AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=DUMMY_ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(DUMMY_PUBLIC_ARTIFACT_URL, dummy_job, 717)
Messages.asBoolean()
Messages.add(DUMMY_STAGE_NAME, DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/1.3.0/717/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 717)
BuildManifest.getArtifactRoot(dummy_job, 717)
uploadTestResults.echo(Uploading to s3://DUMMY_ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=DUMMY_AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=DUMMY_ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(DUMMY_PUBLIC_ARTIFACT_URL, dummy_job, null)
Messages.asBoolean()
Messages.add(DUMMY_STAGE_NAME, DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/1.3.0/null/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ Performance tests with security for 1236 completed})
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 1236)
BuildManifest.getArtifactRoot(perf-test, 1236)
uploadTestResults.echo(Uploading to s3://test_bucket/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=dummy_account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(test://artifact.url, perf-test, 1236)
Messages.asBoolean()
Messages.add(test_stage, test://artifact.url/perf-test/1.3.0/1236/linux/x64/tar/test-results/)
Expand Down Expand Up @@ -138,9 +141,12 @@ Performance tests without security for 1236 completed})
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 1236)
BuildManifest.getArtifactRoot(perf-test, 1236)
uploadTestResults.echo(Uploading to s3://test_bucket/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=dummy_account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(test://artifact.url, perf-test, 1236)
Messages.asBoolean()
Messages.add(test_stage, test://artifact.url/perf-test/1.3.0/1236/linux/x64/tar/test-results/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ Performance tests without security for 1236 completed})
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 1236)
BuildManifest.getArtifactRoot(perf-test, 1236)
uploadTestResults.echo(Uploading to s3://test_bucket/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=dummy_account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=test_bucket, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/perf-test/1.3.0/1236/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=perf-test/1.3.0/1236/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(test://artifact.url, perf-test, 1236)
Messages.asBoolean()
Messages.add(test_stage, test://artifact.url/perf-test/1.3.0/1236/linux/x64/tar/test-results/)
Expand Down
9 changes: 6 additions & 3 deletions tests/jenkins/jobs/UploadTestResults_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
BuildManifest.asBoolean()
uploadTestResults.echo(Build Id: 717)
BuildManifest.getArtifactRoot(dummy_job, 717)
uploadTestResults.echo(Uploading to s3://DUMMY_ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=DUMMY_AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=DUMMY_ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
uploadTestResults.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadTestResults.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadTestResults.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadTestResults.echo(Uploading to s3://ARTIFACT_BUCKET_NAME/dummy_job/1.3.0/717/linux/x64/tar)
uploadTestResults.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadTestResults.s3Upload({file=test-results, bucket=ARTIFACT_BUCKET_NAME, path=dummy_job/1.3.0/717/linux/x64/tar/test-results})
BuildManifest.getArtifactRootUrl(DUMMY_PUBLIC_ARTIFACT_URL, dummy_job, null)
Messages.asBoolean()
Messages.add(DUMMY_STAGE_NAME, DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/1.3.0/null/linux/x64/tar/test-results/)
Expand Down
4 changes: 4 additions & 0 deletions tests/jenkins/lib-testers/UploadTestResultsLibTester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class UploadTestResultsLibTester extends LibFunctionTester {
binding.setVariable('ARTIFACT_BUCKET_NAME', 'DUMMY_ARTIFACT_BUCKET_NAME')
binding.setVariable('PUBLIC_ARTIFACT_URL', 'DUMMY_PUBLIC_ARTIFACT_URL')
binding.setVariable('STAGE_NAME', 'DUMMY_STAGE_NAME')
helper.registerAllowedMethod("withCredentials", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
Expand Down
16 changes: 10 additions & 6 deletions vars/uploadTestResults.groovy
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
void call(Map args = [:]) {
def lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm))
def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))

def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: args.buildManifestFileName))

String buildId = buildManifest.build.id
echo "Build Id: ${buildId}"

def artifactPath = buildManifest.getArtifactRoot(args.jobName, buildId)
echo "Uploading to s3://${ARTIFACT_BUCKET_NAME}/${artifactPath}"
withCredentials([
string(credentialsId: 'jenkins-artifact-bucket-name', variable: 'ARTIFACT_BUCKET_NAME'),
string(credentialsId: 'jenkins-aws-account-public', variable: 'AWS_ACCOUNT_PUBLIC')]) {
echo "Uploading to s3://${ARTIFACT_BUCKET_NAME}/${artifactPath}"

withAWS(role: 'opensearch-test', roleAccount: "${AWS_ACCOUNT_PUBLIC}", duration: 900, roleSessionName: 'jenkins-session') {
s3Upload(file: 'test-results', bucket: "${ARTIFACT_BUCKET_NAME}", path: "${artifactPath}/test-results")
}
withAWS(role: 'opensearch-test', roleAccount: "${AWS_ACCOUNT_PUBLIC}", duration: 900, roleSessionName: 'jenkins-session') {
s3Upload(file: 'test-results', bucket: "${ARTIFACT_BUCKET_NAME}", path: "${artifactPath}/test-results")
}
}

def baseUrl = buildManifest.getArtifactRootUrl("${PUBLIC_ARTIFACT_URL}", args.jobName, args.buildNumber)
lib.jenkins.Messages.new(this).add("${STAGE_NAME}", "${baseUrl}/test-results/")
Expand Down

0 comments on commit d36e73f

Please sign in to comment.