Skip to content

Commit

Permalink
upload index.json from artifacts upload (#1622)
Browse files Browse the repository at this point in the history
* upload index.json from artifacts upload

Signed-off-by: Tianle Huang <tianleh@amazon.com>
  • Loading branch information
tianleh authored Feb 17, 2022
1 parent e0a34eb commit 1b18900
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/jenkins/BuildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class BuildManifest implements Serializable {
this.build.architecture
].join("/")
}

public String getIndexFileRoot(String jobName) {
return [
jobName,
this.build.version
].join("/")
}

public String getArtifactRootUrl(String publicArtifactUrl = 'https://ci.opensearch.org/ci/dbc', String jobName, String buildNumber) {
return [
Expand Down
1 change: 1 addition & 0 deletions tests/jenkins/TestArchiveAssembleUpload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestArchiveAssembleUpload extends BuildPipelineTest {
binding.setVariable('ARTIFACT_UPLOAD_ROLE_NAME', 'upload_role')

helper.registerAllowedMethod("s3Upload", [Map])
helper.registerAllowedMethod("writeJSON", [Map])
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
Expand Down
1 change: 1 addition & 0 deletions tests/jenkins/TestAssembleUpload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TestAssembleUpload extends BuildPipelineTest {
binding.setVariable('ARTIFACT_UPLOAD_ROLE_NAME', 'upload_role')

helper.registerAllowedMethod("s3Upload", [Map])
helper.registerAllowedMethod("writeJSON", [Map])
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
Expand Down
1 change: 1 addition & 0 deletions tests/jenkins/TestBuildAssembleUpload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TestBuildAssembleUpload extends BuildPipelineTest {
})

helper.registerAllowedMethod("s3Upload", [Map])
helper.registerAllowedMethod("writeJSON", [Map])
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
Expand Down
6 changes: 6 additions & 0 deletions tests/jenkins/jobs/ArchiveAssembleUpload_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
uploadArtifacts.uploadToS3({sourcePath=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
BuildManifest.getIndexFileRoot(vars-build)
uploadArtifacts.writeJSON({file=index.json, json={latest=33}})
uploadArtifacts.echo(Uploading index.json to s3://bucket/vars-build/1.1.0)
uploadArtifacts.uploadToS3({sourcePath=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadArtifacts.echo(Uploading to s3://bucket/vars-build/1.1.0/33/linux/x64)
uploadArtifacts.withAWS({role=role, roleAccount=dummy, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadArtifacts.s3Upload({file=builds/opensearch/dist/opensearch-min-1.1.0-linux-x64.tar.gz, bucket=bucket, path=release-candidates/core/opensearch/1.1.0/})
Expand Down
6 changes: 6 additions & 0 deletions tests/jenkins/jobs/AssembleUpload_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
uploadArtifacts.uploadToS3({sourcePath=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
BuildManifest.getIndexFileRoot(vars-build)
uploadArtifacts.writeJSON({file=index.json, json={latest=33}})
uploadArtifacts.echo(Uploading index.json to s3://bucket/vars-build/1.1.0)
uploadArtifacts.uploadToS3({sourcePath=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadArtifacts.echo(Uploading to s3://bucket/vars-build/1.1.0/33/linux/x64)
uploadArtifacts.withAWS({role=role, roleAccount=dummy, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadArtifacts.s3Upload({file=builds/opensearch/dist/opensearch-min-1.1.0-linux-x64.tar.gz, bucket=bucket, path=release-candidates/core/opensearch/1.1.0/})
Expand Down
6 changes: 6 additions & 0 deletions tests/jenkins/jobs/BuildAssembleUpload_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
uploadArtifacts.uploadToS3({sourcePath=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=dist, bucket=artifact-bucket, path=vars-build/1.1.0/33/linux/x64/dist})
BuildManifest.getIndexFileRoot(vars-build)
uploadArtifacts.writeJSON({file=index.json, json={latest=33}})
uploadArtifacts.echo(Uploading index.json to s3://bucket/vars-build/1.1.0)
uploadArtifacts.uploadToS3({sourcePath=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadToS3.withAWS({role=upload_role, roleAccount=account, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadToS3.s3Upload({file=index.json, bucket=artifact-bucket, path=vars-build/1.1.0/index.json})
uploadArtifacts.echo(Uploading to s3://bucket/vars-build/1.1.0/33/linux/x64)
uploadArtifacts.withAWS({role=role, roleAccount=dummy, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
uploadArtifacts.s3Upload({file=builds/opensearch/dist/opensearch-min-1.1.0-linux-x64.tar.gz, bucket=bucket, path=release-candidates/core/opensearch/1.1.0/})
Expand Down
1 change: 1 addition & 0 deletions tests/jenkins/jobs/BuildManifest_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pipeline {
echo buildManifest.getArtifactUrl('https://ci.opensearch.org/ci/dbc', 'bundle-build', '1')
echo buildManifest.build.getPackageName()
echo buildManifest.components.getMinArtifact()
echo buildManifest.getIndexFileRoot("distribution-build-opensearch")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
BuildManifest_Jenkinsfile.echo(opensearch-1.1.0-linux-x64.tar.gz)
BuildManifest.getMinArtifact()
BuildManifest_Jenkinsfile.echo(dist/opensearch-min-1.1.0-linux-x64.tar.gz)
BuildManifest.getIndexFileRoot(distribution-build-opensearch)
BuildManifest_Jenkinsfile.echo(distribution-build-opensearch/1.1.0)
12 changes: 12 additions & 0 deletions vars/uploadArtifacts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ void call(Map args = [:]) {
path: "${artifactPath}/dist"
)

def indexFilePath = buildManifest.getIndexFileRoot("${JOB_NAME}")
def latestBuildData = ['latest': "${BUILD_NUMBER}"]
writeJSON file: 'index.json', json: latestBuildData

echo "Uploading index.json to s3://${ARTIFACT_PRODUCTION_BUCKET_NAME}/${indexFilePath}"

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

echo "Uploading to s3://${ARTIFACT_PRODUCTION_BUCKET_NAME}/${artifactPath}"

withAWS(role: "${ARTIFACT_PROMOTION_ROLE_NAME}", roleAccount: "${AWS_ACCOUNT_ARTIFACT}", duration: 900, roleSessionName: 'jenkins-session') {
Expand Down

0 comments on commit 1b18900

Please sign in to comment.