Skip to content

Commit

Permalink
Make parameters more generic
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Jan 18, 2024
1 parent a20f2fb commit d9b1d36
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/RetrievePreviousBuild_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pipeline {
distribution: "tar",
architecture: "x64",
platform: "linux",
incremental: "123"
previousBuildId: "123"
)
retrievePreviousBuild(
inputManifest: "tests/data/opensearch-dashboards-input-2.12.0.yml",
distribution: "zip",
architecture: "x64",
platform: "windows",
incremental: "1234"
previousBuildId: "1234"
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/jobs/RetrievePreviousBuild_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RetrievePreviousBuild_Jenkinsfile.echo(Executing on agent [label:none])
RetrievePreviousBuild_Jenkinsfile.stage(Test build manifest jenkins var, groovy.lang.Closure)
RetrievePreviousBuild_Jenkinsfile.script(groovy.lang.Closure)
RetrievePreviousBuild_Jenkinsfile.retrievePreviousBuild({inputManifest=tests/data/opensearch-input-2.12.0.yml, distribution=tar, architecture=x64, platform=linux, incremental=123})
RetrievePreviousBuild_Jenkinsfile.retrievePreviousBuild({inputManifest=tests/data/opensearch-input-2.12.0.yml, distribution=tar, architecture=x64, platform=linux, previousBuildId=123})
retrievePreviousBuild.legacySCM(groovy.lang.Closure)
retrievePreviousBuild.library({identifier=jenkins@main, retriever=null})
retrievePreviousBuild.readYaml({file=tests/data/opensearch-input-2.12.0.yml})
Expand All @@ -18,7 +18,7 @@
retrievePreviousBuild.sh(mkdir -p tar && mv -v /tmp/workspace/download/dummy_job/2.12.0/123/linux/x64/tar /tmp/workspace)
retrievePreviousBuild.echo(Setting up Maven Local for OpenSearch build.)
retrievePreviousBuild.sh(mkdir -p ~/.m2/repository/org/ && cp -r tar/builds/opensearch/maven/org/opensearch/ ~/.m2/repository/org/)
RetrievePreviousBuild_Jenkinsfile.retrievePreviousBuild({inputManifest=tests/data/opensearch-dashboards-input-2.12.0.yml, distribution=zip, architecture=x64, platform=windows, incremental=1234})
RetrievePreviousBuild_Jenkinsfile.retrievePreviousBuild({inputManifest=tests/data/opensearch-dashboards-input-2.12.0.yml, distribution=zip, architecture=x64, platform=windows, previousBuildId=1234})
retrievePreviousBuild.legacySCM(groovy.lang.Closure)
retrievePreviousBuild.library({identifier=jenkins@main, retriever=null})
retrievePreviousBuild.readYaml({file=tests/data/opensearch-dashboards-input-2.12.0.yml})
Expand Down
10 changes: 5 additions & 5 deletions tests/jenkins/lib-testers/RetrievePreviousBuildLibTester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class RetrievePreviousBuildLibTester extends LibFunctionTester {
private String distribution = 'tar'
private String platform = 'linux'
private String architecture = 'tar'
private String incremental = 'latest'
private String previousBuildId = 'latest'

public RetrievePreviousBuildLibTester(String inputManifestPath, String platform, String architecture, String distribution, String incremental){
public RetrievePreviousBuildLibTester(String inputManifestPath, String platform, String architecture, String distribution, String previousBuildId){
this.inputManifestPath = inputManifestPath
this.platform = platform
this.architecture = architecture
this.distribution = distribution
this.incremental = incremental
this.previousBuildId = previousBuildId
}

@Override
Expand All @@ -35,7 +35,7 @@ class RetrievePreviousBuildLibTester extends LibFunctionTester {
assertThat(call.args.platform.first(), notNullValue())
assertThat(call.args.architecture.first(), notNullValue())
assertThat(call.args.distribution.first(), notNullValue())
assertThat(call.args.incremental.first(), notNullValue())
assertThat(call.args.previousBuildId.first(), notNullValue())
}

@Override
Expand All @@ -44,7 +44,7 @@ class RetrievePreviousBuildLibTester extends LibFunctionTester {
&& call.args.platform.first().equals(this.platform)
&& call.args.architecture.first().equals(this.architecture)
&& call.args.distribution.first().equals(this.distribution)
&& call.args.incremental.first().equals(this.incremental)
&& call.args.previousBuildId.first().equals(this.previousBuildId)
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions vars/buildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
@param args.snapshot <optional> - Boolean value. Defaults to null.
@param args.lock <optional> - Generate a stable reference manifest. Defaults to null.
@param args.continueOnError <optional> - Do not fail the distribution build on any plugin component failure. Defaults to null
@param args.incremental <optional> - Boolean value to enable incremental build.
*/
void call(Map args = [:]) {
boolean incremental_enabled = args.incremental != null && !args.incremental.isEmpty() && !args.incremental.equalsIgnoreCase("false")
boolean incremental_enabled = args.incremental != null && args.incremental

if (incremental_enabled) {
echo("Incremental build enabled! Retrieving previous build library")
echo("Incremental build enabled! Retrieving previous build library.")
retrievePreviousBuild(args)
}

Expand Down
19 changes: 10 additions & 9 deletions vars/retrievePreviousBuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,39 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/** Library to download previous build artifacts used for incremental build.
/** Library to download previous build artifacts into the workspace.
@param Map args = [:] args A map of the following parameters
@param args.inputManifest <required> - Relative path to input manifest containing all the components to build.
@param args.jobName <optional> - Relative path to input manifest containing all the components to build.
@param args.platform <required> - Platform of previous build to retrieve.
@param args.architecture <required> - Architecture of previous build to retrieve.
@param args.distribution <required> - Distribution of previous build to retrieve.
@param args.incremental <required> - String value contains the build number of previous build or the latest.
@param args.previousBuildId <optional> - Build id of previous build for incremental build. Defaults to latest.
*/
void call(Map args = [:]) {
def lib = library(identifier: 'jenkins@main', retriever: legacySCM(scm))
def inputManifestObj = lib.jenkins.InputManifest.new(readYaml(file: args.inputManifest))

def DISTRIBUTION_JOB_NAME = "${JOB_NAME}"
def revision = inputManifestObj.build.version
def DISTRIBUTION_JOB_NAME = args.jobName ? args.jobName : "${JOB_NAME}"
def version = inputManifestObj.build.version

def DISTRIBUTION_PLATFORM = args.platform
def DISTRIBUTION_ARCHITECTURE = args.architecture
def distribution = args.distribution
def prefixPath = "${WORKSPACE}/download"
def DISTRIBUTION_BUILD_NUMBER

if (args.incremental.equalsIgnoreCase("latest")) {
if (args.previousBuildId.equalsIgnoreCase("latest")) {
DISTRIBUTION_BUILD_NUMBER = sh(
script: "curl -sL https://ci.opensearch.org/ci/dbc/${DISTRIBUTION_JOB_NAME}/${revision}/index.json | jq -r \".latest\"",
script: "curl -sL https://ci.opensearch.org/ci/dbc/${DISTRIBUTION_JOB_NAME}/${version}/index.json | jq -r \".latest\"",
returnStdout: true
).trim()
//Once we have new index.json, URL will be changed to: https://ci.opensearch.org/ci/dbc/${DISTRIBUTION_JOB_NAME}/${revision}/index/${platform}/${architecture}/${distribution}/index.json
//Once we have new index.json, URL will be changed to: https://ci.opensearch.org/ci/dbc/${DISTRIBUTION_JOB_NAME}/${version}/index/${platform}/${architecture}/${distribution}/index.json
} else {
DISTRIBUTION_BUILD_NUMBER = args.incremental
DISTRIBUTION_BUILD_NUMBER = args.previousBuildId
}

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

withCredentials([string(credentialsId: 'jenkins-artifact-bucket-name', variable: 'ARTIFACT_BUCKET_NAME')]) {
downloadFromS3(
Expand Down

0 comments on commit d9b1d36

Please sign in to comment.