diff --git a/src/jenkins/BuildManifest.groovy b/src/jenkins/BuildManifest.groovy index 6a613a944e..9026d475e2 100644 --- a/src/jenkins/BuildManifest.groovy +++ b/src/jenkins/BuildManifest.groovy @@ -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 [ diff --git a/tests/jenkins/TestArchiveAssembleUpload.groovy b/tests/jenkins/TestArchiveAssembleUpload.groovy index f8e269ce3a..09abc27ed0 100644 --- a/tests/jenkins/TestArchiveAssembleUpload.groovy +++ b/tests/jenkins/TestArchiveAssembleUpload.groovy @@ -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) diff --git a/tests/jenkins/TestAssembleUpload.groovy b/tests/jenkins/TestAssembleUpload.groovy index d25f203230..c6fc12c950 100644 --- a/tests/jenkins/TestAssembleUpload.groovy +++ b/tests/jenkins/TestAssembleUpload.groovy @@ -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) diff --git a/tests/jenkins/TestBuildAssembleUpload.groovy b/tests/jenkins/TestBuildAssembleUpload.groovy index a9103fe2f3..c493b72110 100644 --- a/tests/jenkins/TestBuildAssembleUpload.groovy +++ b/tests/jenkins/TestBuildAssembleUpload.groovy @@ -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) diff --git a/tests/jenkins/jobs/ArchiveAssembleUpload_Jenkinsfile.txt b/tests/jenkins/jobs/ArchiveAssembleUpload_Jenkinsfile.txt index c38e8796a6..ad5f4eb217 100644 --- a/tests/jenkins/jobs/ArchiveAssembleUpload_Jenkinsfile.txt +++ b/tests/jenkins/jobs/ArchiveAssembleUpload_Jenkinsfile.txt @@ -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/}) diff --git a/tests/jenkins/jobs/AssembleUpload_Jenkinsfile.txt b/tests/jenkins/jobs/AssembleUpload_Jenkinsfile.txt index 10ef941999..5181cdbc30 100644 --- a/tests/jenkins/jobs/AssembleUpload_Jenkinsfile.txt +++ b/tests/jenkins/jobs/AssembleUpload_Jenkinsfile.txt @@ -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/}) diff --git a/tests/jenkins/jobs/BuildAssembleUpload_Jenkinsfile.txt b/tests/jenkins/jobs/BuildAssembleUpload_Jenkinsfile.txt index c9113989df..dbfb513e8b 100644 --- a/tests/jenkins/jobs/BuildAssembleUpload_Jenkinsfile.txt +++ b/tests/jenkins/jobs/BuildAssembleUpload_Jenkinsfile.txt @@ -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/}) diff --git a/tests/jenkins/jobs/BuildManifest_Jenkinsfile b/tests/jenkins/jobs/BuildManifest_Jenkinsfile index 4fab50e345..93a95aefab 100644 --- a/tests/jenkins/jobs/BuildManifest_Jenkinsfile +++ b/tests/jenkins/jobs/BuildManifest_Jenkinsfile @@ -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") } } } diff --git a/tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt b/tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt index 5dcece6e36..cc36de6ae0 100644 --- a/tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt +++ b/tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt @@ -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) diff --git a/vars/uploadArtifacts.groovy b/vars/uploadArtifacts.groovy index 0bf300969a..6447f9cd28 100644 --- a/vars/uploadArtifacts.groovy +++ b/vars/uploadArtifacts.groovy @@ -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') {