Skip to content

Commit

Permalink
Refactoring var scopes in uploadMinSnapshotsToS3 libs
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon committed Sep 19, 2023
1 parent 63eb337 commit 85070bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
34 changes: 11 additions & 23 deletions tests/jenkins/jobs/uploadMinSnapshotsToS3_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
19 changes: 10 additions & 9 deletions vars/uploadMinSnapshotsToS3.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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}
Expand Down

0 comments on commit 85070bf

Please sign in to comment.