Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update uploadIndexFile lib env vars with credentials #2247

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tianleh can you review this. It looked like a bug in echo statement before so I changed it.
Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.


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