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

upload index.json from artifacts upload #1622

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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
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