Skip to content

Commit

Permalink
Add opensearch promotion workflow and jenkins libs for tar (#1354)
Browse files Browse the repository at this point in the history
* Add opensearch promotion workflow and jenkins libs for tar

Signed-off-by: Peter Zhu <[email protected]>
  • Loading branch information
peterzhuamazon authored Dec 16, 2021
1 parent 99dfb20 commit 9c9ee06
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
60 changes: 60 additions & 0 deletions jenkins/promotion/tar-promotion.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm))

pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
agent none
parameters {
choice(
choices: ['distribution-build-opensearch', 'distribution-build-opensearch-dashboards'],
name: 'DISTRIBUTION_JOB_NAME',
description: 'What platform is this distribution build for?.'
)
string(
defaultValue: '',
name: 'DISTRIBUTION_BUILD_NUMBER',
description: 'What is the build id of the above DISTRIBUTION_JOB_NAME that you want to promote? (e.g. 123, 136)',
trim: true
)
string(
defaultValue: '',
name: 'INPUT_MANIFEST',
description: 'What is the input manifest of the above DISTRIBUTION_JOB_NAME that you want to promote? (e.g. 1.2.2/opensearch-1.2.2.yml)',
trim: true
)
choice(
choices: ['linux', 'windows', 'darwin'],
name: 'DISTRIBUTION_PLATFORM',
description: 'What platform is this distribution build for?.'
)
choice(
choices: ['x64', 'arm64'],
name: 'DISTRIBUTION_ARCHITECTURE',
description: 'What architecture is this distribution build for?.'
)
}
stages {
stage('promote artifacts') {
agent {
docker {
label 'Jenkins-Agent-al2-x64-c54xlarge-Docker-Host'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk14'
alwaysPull true
}
}
steps {
script {
promoteArtifacts()
}
}
post() {
always {
script {
cleanWs disableDeferredWipeout: true, deleteDirs: true
}
}
}
}
}
}
53 changes: 53 additions & 0 deletions vars/promoteArtifacts.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

void call(Map args = [:]) {
git url: 'https://github.com/opensearch-project/opensearch-build.git', branch: 'main'
def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))

String manifest = args.manifest ?: "manifests/${INPUT_MANIFEST}"
def inputManifest = lib.jenkins.InputManifest.new(readYaml(file: manifest))
String filename = inputManifest.build.getFilename()
String version = inputManifest.build.version

def artifactPath = "${DISTRIBUTION_JOB_NAME}/${version}/${DISTRIBUTION_BUILD_NUMBER}/${DISTRIBUTION_PLATFORM}/${DISTRIBUTION_ARCHITECTURE}"

withAWS(role: "${ARTIFACT_DOWNLOAD_ROLE_NAME}", roleAccount: "${AWS_ACCOUNT_PUBLIC}", duration: 900, roleSessionName: 'jenkins-session') {
s3Download(bucket: "${ARTIFACT_BUCKET_NAME}", file: "$WORKSPACE/artifacts", path: "${artifactPath}/", force: true)
}

String build_manifest = "artifacts/$artifactPath/builds/$filename/manifest.yml"
def buildManifest = readYaml(file: build_manifest)

withAWS(role: "${ARTIFACT_PROMOTION_ROLE_NAME}", roleAccount: "${AWS_ACCOUNT_ARTIFACT}", duration: 900, roleSessionName: 'jenkins-session') {
// Core Plugins
println("Start Core Plugin Promotion to artifects.opensearch.org Bucket")
List<String> corePluginList = buildManifest.components.artifacts."core-plugins"[0]
for (String pluginSubPath : corePluginList) {
String pluginSubFolder = pluginSubPath.split('/')[0]
String pluginNameWithExt = pluginSubPath.split('/')[1]
String pluginName = pluginNameWithExt.replace('-' + version + '.zip', '')
String pluginFullPath = ['plugins', pluginName, version].join('/')
s3Upload(bucket: "${ARTIFACT_PRODUCTION_BUCKET_NAME}", path: "releases/$pluginFullPath/", workingDir: "$WORKSPACE/artifacts/$artifactPath/builds/$filename/$pluginSubFolder/"
, includePathPattern: "**/${pluginName}*")
}


// Tar Core/Bundle
println("Start Tar Core/Bundle Promotion to artifacts.opensearch.org Bucket")
String coreFullPath = ['core', filename, version].join('/')
String bundleFullPath = ['bundle', filename, version].join('/')
s3Upload(bucket: "${ARTIFACT_PRODUCTION_BUCKET_NAME}", path: "releases/$coreFullPath/", workingDir: "$WORKSPACE/artifacts/$artifactPath/builds/$filename/dist/"
, includePathPattern: "**/${filename}-min-${version}*")
s3Upload(bucket: "${ARTIFACT_PRODUCTION_BUCKET_NAME}", path: "releases/$bundleFullPath/", workingDir: "$WORKSPACE/artifacts/$artifactPath/dist/$filename/"
, includePathPattern: "**/${filename}*-${version}*")


}

}

0 comments on commit 9c9ee06

Please sign in to comment.