Skip to content

Commit

Permalink
Update uploadIndexFile lib env vars with credentials (#2247)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Jun 24, 2022
1 parent 6d4f71d commit a3626e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/jenkins/TestUploadIndexFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestUploadIndexFile extends BuildPipelineTest {
@Before
void setUp() {
this.registerLibTester(new UploadIndexFileLibTester('test'))
this.registerLibTester(new UploadToS3LibTester('index.json', 'dummy_bucket_name', 'test/index.json'))
this.registerLibTester(new UploadToS3LibTester('index.json', 'ARTIFACT_BUCKET_NAME', 'test/index.json'))

super.setUp()
}
Expand Down
14 changes: 8 additions & 6 deletions tests/jenkins/jobs/UploadIndexFile_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
UploadIndexFile_Jenkinsfile.script(groovy.lang.Closure)
UploadIndexFile_Jenkinsfile.uploadIndexFile({indexFilePath=test})
uploadIndexFile.writeJSON({file=index.json, json={latest=123}})
uploadIndexFile.echo(Uploading index.json to s3://dummy_bucket_name/test)
uploadIndexFile.uploadToS3({sourcePath=index.json, bucket=dummy_bucket_name, path=test/index.json})
uploadToS3.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadToS3.withCredentials([AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadToS3.withAWS({role=opensearch-bundle, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=index.json, bucket=dummy_bucket_name, path=test/index.json})
uploadIndexFile.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
uploadIndexFile.withCredentials([ARTIFACT_BUCKET_NAME], groovy.lang.Closure)
uploadIndexFile.echo(Uploading index.json to s3://ARTIFACT_BUCKET_NAME/test)
uploadIndexFile.uploadToS3({sourcePath=index.json, bucket=ARTIFACT_BUCKET_NAME, path=test/index.json})
uploadToS3.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
uploadToS3.withCredentials([AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
uploadToS3.withAWS({role=opensearch-bundle, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=index.json, bucket=ARTIFACT_BUCKET_NAME, path=test/index.json})
7 changes: 6 additions & 1 deletion tests/jenkins/lib-testers/UploadIndexFileLibTester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class UploadIndexFileLibTester extends LibFunctionTester {

void configure(helper, binding) {
binding.setVariable('BUILD_NUMBER', '123')
binding.setVariable('ARTIFACT_PRODUCTION_BUCKET_NAME', 'dummy_bucket_name')
binding.setVariable('ARTIFACT_BUCKET_NAME', 'dummy_bucket_name')

helper.registerAllowedMethod("withCredentials", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})

helper.registerAllowedMethod("writeJSON", [Map])
}
Expand Down
10 changes: 6 additions & 4 deletions vars/uploadIndexFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ void call(Map args = [:]) {
def latestBuildData = ['latest': "${BUILD_NUMBER}"]
writeJSON file: 'index.json', json: latestBuildData

echo "Uploading index.json to s3://${ARTIFACT_PRODUCTION_BUCKET_NAME}/${args.indexFilePath}"
withCredentials([string(credentialsId: 'jenkins-artifact-bucket-name', variable: 'ARTIFACT_BUCKET_NAME')]) {
echo "Uploading index.json to s3://${ARTIFACT_BUCKET_NAME}/${args.indexFilePath}"

uploadToS3(
uploadToS3(
sourcePath: 'index.json',
bucket: "${ARTIFACT_BUCKET_NAME}",
path: "${args.indexFilePath}/index.json"
)
}
)
}
}

0 comments on commit a3626e6

Please sign in to comment.