From 85070bf2de498d2a3f6708e9579cd266417c571c Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 19 Sep 2023 17:10:01 +0000 Subject: [PATCH] Refactoring var scopes in uploadMinSnapshotsToS3 libs Signed-off-by: Peter Zhu --- .../uploadMinSnapshotsToS3_Jenkinsfile.txt | 34 ++++++------------- vars/uploadMinSnapshotsToS3.groovy | 19 ++++++----- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt b/tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt index 19c737d5c..b599dbebe 100644 --- a/tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt +++ b/tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt @@ -13,33 +13,21 @@ uploadMinSnapshotsToS3.readYaml({file=tests/data/tar/builds/opensearch/manifest.yml}) BuildManifest.asBoolean() uploadMinSnapshotsToS3.echo(Create .sha512 for Min Snapshots Artifacts) - createSha512Checksums.sh({script=find tests/data/tar/builds/opensearch/dist -type f, returnStdout=true}) - createSha512Checksums.echo(Creating sha for opensearch-min-1.3.0-linux-x64.tar.gz) - createSha512Checksums.sh({script=sha512sum opensearch-min-1.3.0-linux-x64.tar.gz, returnStdout=true}) - createSha512Checksums.sh({script=basename ccc, returnStdout=true}) - createSha512Checksums.writeFile({file=opensearch-min-1.3.0-linux-x64.tar.gz.sha512, text=bbb -bbb -ccc -}) - createSha512Checksums.echo(Creating sha for opensearch-dashboards-min-1.3.0-linux-x64.tar.gz) - createSha512Checksums.sh({script=sha512sum opensearch-dashboards-min-1.3.0-linux-x64.tar.gz, returnStdout=true}) - createSha512Checksums.sh({script=basename ccc, returnStdout=true}) - createSha512Checksums.writeFile({file=opensearch-dashboards-min-1.3.0-linux-x64.tar.gz.sha512, text=bbb -bbb -ccc -}) - uploadMinSnapshotsToS3.echo(Start copying files) + createSha512Checksums.sh({script=find tests/data/null/builds/opensearch/dist -type f, returnStdout=true}) + createSha512Checksums.echo(Not generating sha for bbb in tests/data/null/builds/opensearch/dist, doesn't match allowed types [.tar.gz, .zip, .rpm, .deb]) + createSha512Checksums.echo(Not generating sha for ccc in tests/data/null/builds/opensearch/dist, doesn't match allowed types [.tar.gz, .zip, .rpm, .deb]) + uploadMinSnapshotsToS3.echo(Start copying files: ver-1.2.2-SNAPSHOT arch-x64 plat-linux build-29 dist-null ext-tar.gz) uploadMinSnapshotsToS3.sh( - cp -v tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz - cp -v tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz.sha512 tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512 - cp -v tests/data/tar/builds/opensearch/dist/../manifest.yml tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml - sed -i "s/.tar.gz/-latest.tar.gz/g" tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512 + cp -v tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz + cp -v tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64.tar.gz.sha512 tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512 + cp -v tests/data/null/builds/opensearch/dist/../manifest.yml tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml + sed -i "s/.tar.gz/-latest.tar.gz/g" tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512 ) uploadMinSnapshotsToS3.string({credentialsId=jenkins-artifact-promotion-role, variable=ARTIFACT_PROMOTION_ROLE_NAME}) uploadMinSnapshotsToS3.string({credentialsId=jenkins-aws-production-account, variable=AWS_ACCOUNT_ARTIFACT}) uploadMinSnapshotsToS3.string({credentialsId=jenkins-artifact-production-bucket-name, variable=ARTIFACT_PRODUCTION_BUCKET_NAME}) uploadMinSnapshotsToS3.withCredentials([ARTIFACT_PROMOTION_ROLE_NAME, AWS_ACCOUNT_ARTIFACT, ARTIFACT_PRODUCTION_BUCKET_NAME], groovy.lang.Closure) uploadMinSnapshotsToS3.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure) - uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz}) - uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512}) - uploadMinSnapshotsToS3.s3Upload({file=tests/data/tar/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml}) + uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz}) + uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.sha512}) + uploadMinSnapshotsToS3.s3Upload({file=tests/data/null/builds/opensearch/dist/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml, bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=snapshots/core/opensearch/1.2.2-SNAPSHOT/opensearch-min-1.2.2-SNAPSHOT-linux-x64-latest.tar.gz.build-manifest.yml}) diff --git a/vars/uploadMinSnapshotsToS3.groovy b/vars/uploadMinSnapshotsToS3.groovy index cf1432212..9616acda6 100644 --- a/vars/uploadMinSnapshotsToS3.groovy +++ b/vars/uploadMinSnapshotsToS3.groovy @@ -12,21 +12,22 @@ void call(Map args = [:]) { String manifest = args.manifest ?: "manifests/${INPUT_MANIFEST}" def inputManifest = lib.jenkins.InputManifest.new(readYaml(file: manifest)) - echo("Retreving build manifest from: $WORKSPACE/${args.distribution}/builds/${inputManifest.build.getFilename()}/manifest.yml") + String productName = inputManifest.build.getFilename() + echo("Retreving build manifest from: $WORKSPACE/${args.distribution}/builds/${productName}/manifest.yml") - productName = inputManifest.build.getFilename() def buildManifest = lib.jenkins.BuildManifest.new(readYaml(file: "$WORKSPACE/${args.distribution}/builds/${productName}/manifest.yml")) - version = buildManifest.build.version - architecture = buildManifest.build.architecture - platform = buildManifest.build.platform - id = buildManifest.build.id - extension = buildManifest.build.getExtension() + String version = buildManifest.build.version + String architecture = buildManifest.build.architecture + String platform = buildManifest.build.platform + String id = buildManifest.build.id + String distribution = buildManifest.build.distribution + String extension = buildManifest.build.getExtension() // Setup src & dst variables for artifacts // Replace backslash with forward slash ('\' to '/') in path // Compatible with both Windows as well as any nix* env // Else the map in groovy will treat '\' as escape char on Windows - String srcDir = "${WORKSPACE}/${args.distribution}/builds/${productName}/dist".replace("\\", "/") + String srcDir = "${WORKSPACE}/${distribution}/builds/${productName}/dist".replace("\\", "/") String dstDir = "snapshots/core/${productName}/${version}" String baseName = "${productName}-min-${version}-${platform}-${architecture}" @@ -38,7 +39,7 @@ void call(Map args = [:]) { action(argsMap) } - echo('Start copying files') + echo("Start copying files: ver-${version} arch-${architecture} plat-${platform} build-${id} dist-${distribution} ext-${extension}") sh """ cp -v ${srcDir}/${baseName}.${extension} ${srcDir}/${baseName}-latest.${extension}