diff --git a/build.gradle b/build.gradle index 9d604a04..326e07f4 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ jacocoTestReport { } } -String version = '6.5.2' +String version = '6.6.0' task updateVersion { doLast { diff --git a/tests/jenkins/TestRunGradleCheck.groovy b/tests/jenkins/TestRunGradleCheck.groovy index c9675472..a0c538ae 100644 --- a/tests/jenkins/TestRunGradleCheck.groovy +++ b/tests/jenkins/TestRunGradleCheck.groovy @@ -11,6 +11,11 @@ import jenkins.tests.BuildPipelineTest import org.junit.Before import org.junit.Test +import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString +import static org.hamcrest.CoreMatchers.containsString +import static org.hamcrest.CoreMatchers.hasItem +import static org.hamcrest.MatcherAssert.assertThat + class TestRunGradleCheck extends BuildPipelineTest { @@ -19,6 +24,7 @@ class TestRunGradleCheck extends BuildPipelineTest { this.registerLibTester(new RunGradleCheckLibTester( 'https://github.com/opensearch-project/OpenSearch', 'main', + 'false' ) ) super.setUp() @@ -27,5 +33,49 @@ class TestRunGradleCheck extends BuildPipelineTest { @Test void testRunGradleCheck() { super.testPipeline("tests/jenkins/jobs/RunGradleCheck_Jenkinsfile") + + } + + @Test + void testNoAlignParamInGradleCommand() { + runScript("tests/jenkins/jobs/RunGradleCheck_Jenkinsfile") + + def gradleCommands = getCommandExecutions('sh', 'gradle').findAll { + shCommand -> shCommand.contains('gradle') + } + assertThat(gradleCommands, hasItem(containsString("./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1") + )) + } + + @Test + void testRunGradleCheckBwcAlign() { + super.testPipeline("tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile") + } + + @Test + void testAlignParamInGradleCommand() { + runScript("tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile") + + def gradleCommands = getCommandExecutions('sh', 'gradle').findAll { + shCommand -> shCommand.contains('gradle') + } + assertThat(gradleCommands, hasItem(containsString("./gradlew clean && ./gradlew check -Dtests.coverage=true -Dbwc.checkout.align=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1") + )) + } + + def getCommandExecutions(methodName, command) { + def shCommands = helper.callStack.findAll { + call -> + call.methodName == methodName + }. + collect { + call -> + callArgsToString(call) + }.findAll { + shCommand -> + shCommand.contains(command) + } + + return shCommands } } diff --git a/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile b/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile new file mode 100644 index 00000000..f71c1ca9 --- /dev/null +++ b/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile @@ -0,0 +1,25 @@ +/* + * Copyright OpenSearch Contributors + * 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. + */ + +pipeline { + agent none + stages { + stage('gradle-check') { + steps { + script { + runGradleCheck( + gitRepoUrl: "https://github.com/opensearch-project/OpenSearch", + gitReference: "main", + bwcCheckoutAlign: "true" + ) + } + } + } + } +} diff --git a/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile.txt b/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile.txt new file mode 100644 index 00000000..fa2fb9f0 --- /dev/null +++ b/tests/jenkins/jobs/RunGradleCheckBwcAlign_Jenkinsfile.txt @@ -0,0 +1,67 @@ + RunGradleCheckBwcAlign_Jenkinsfile.run() + RunGradleCheckBwcAlign_Jenkinsfile.pipeline(groovy.lang.Closure) + RunGradleCheckBwcAlign_Jenkinsfile.echo(Executing on agent [label:none]) + RunGradleCheckBwcAlign_Jenkinsfile.stage(gradle-check, groovy.lang.Closure) + RunGradleCheckBwcAlign_Jenkinsfile.script(groovy.lang.Closure) + RunGradleCheckBwcAlign_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main, bwcCheckoutAlign=true}) + runGradleCheck.legacySCM(groovy.lang.Closure) + runGradleCheck.library({identifier=jenkins@6.5.2, retriever=null}) + runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-credentials, usernameVariable=amazon_s3_access_key, passwordVariable=amazon_s3_secret_key}) + runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-resources, usernameVariable=amazon_s3_base_path, passwordVariable=amazon_s3_bucket}) + runGradleCheck.withCredentials([[amazon_s3_access_key, amazon_s3_secret_key], [amazon_s3_base_path, amazon_s3_bucket]], groovy.lang.Closure) + runGradleCheck.sh( + #!/bin/bash + + set -e + set +x + + echo "Git clone: https://github.com/opensearch-project/OpenSearch with ref: main" + rm -rf search + git clone https://github.com/opensearch-project/OpenSearch search + cd search/ + git checkout -f main + git rev-parse HEAD + + echo "Get Major Version" + OS_VERSION=`cat buildSrc/version.properties | grep opensearch | cut -d= -f2 | grep -oE '[0-9.]+'` + JDK_MAJOR_VERSION=`cat buildSrc/version.properties | grep "bundled_jdk" | cut -d= -f2 | grep -oE '[0-9]+' | head -n 1` + OS_MAJOR_VERSION=`echo $OS_VERSION | grep -oE '[0-9]+' | head -n 1` + echo "Version: $OS_VERSION, Major Version: $OS_MAJOR_VERSION" + + echo "Using JAVA $JDK_MAJOR_VERSION" + eval export JAVA_HOME='$JAVA'$JDK_MAJOR_VERSION'_HOME' + + env | grep JAVA | grep HOME + + echo "Gradle clean cache and stop existing gradledaemon" + ./gradlew --stop + rm -rf ~/.gradle + + if command -v docker > /dev/null; then + echo "Check existing dockercontainer" + docker ps -a + docker stop `docker ps -qa` > /dev/null 2>&1 || echo + docker rm --force `docker ps -qa` > /dev/null 2>&1 || echo + echo "Stop existing dockercontainer" + docker ps -a + + echo "Check docker-compose version" + docker-compose version + fi + + echo "Check existing processes" + ps -ef | grep [o]pensearch | wc -l + echo "Cleanup existing processes" + kill -9 `ps -ef | grep [o]pensearch | awk '{print $2}'` > /dev/null 2>&1 || echo + ps -ef | grep [o]pensearch | wc -l + + echo "Start gradlecheck" + GRADLE_CHECK_STATUS=0 + ./gradlew clean && ./gradlew check -Dtests.coverage=true -Dbwc.checkout.align=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1 + + if [ "$GRADLE_CHECK_STATUS" != 0 ]; then + echo Gradle Check Failed! + exit 1 + fi + + ) diff --git a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile index 1c91263c..e0eae579 100644 --- a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile +++ b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile @@ -15,7 +15,8 @@ pipeline { script { runGradleCheck( gitRepoUrl: "https://github.com/opensearch-project/OpenSearch", - gitReference: "main" + gitReference: "main", + bwcCheckoutAlign: "false" ) } } diff --git a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt index cde21c96..acad4abc 100644 --- a/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt +++ b/tests/jenkins/jobs/RunGradleCheck_Jenkinsfile.txt @@ -3,7 +3,7 @@ RunGradleCheck_Jenkinsfile.echo(Executing on agent [label:none]) RunGradleCheck_Jenkinsfile.stage(gradle-check, groovy.lang.Closure) RunGradleCheck_Jenkinsfile.script(groovy.lang.Closure) - RunGradleCheck_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main}) + RunGradleCheck_Jenkinsfile.runGradleCheck({gitRepoUrl=https://github.com/opensearch-project/OpenSearch, gitReference=main, bwcCheckoutAlign=false}) runGradleCheck.legacySCM(groovy.lang.Closure) runGradleCheck.library({identifier=jenkins@6.5.2, retriever=null}) runGradleCheck.usernamePassword({credentialsId=jenkins-gradle-check-s3-aws-credentials, usernameVariable=amazon_s3_access_key, passwordVariable=amazon_s3_secret_key}) @@ -57,7 +57,7 @@ echo "Start gradlecheck" GRADLE_CHECK_STATUS=0 - ./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1 + ./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1 if [ "$GRADLE_CHECK_STATUS" != 0 ]; then echo Gradle Check Failed! diff --git a/tests/jenkins/lib-testers/RunGradleCheckLibTester.groovy b/tests/jenkins/lib-testers/RunGradleCheckLibTester.groovy index 267d1cbe..fce84781 100644 --- a/tests/jenkins/lib-testers/RunGradleCheckLibTester.groovy +++ b/tests/jenkins/lib-testers/RunGradleCheckLibTester.groovy @@ -14,10 +14,12 @@ class RunGradleCheckLibTester extends LibFunctionTester { private String gitRepoUrl private String gitReference + private String bwcCheckoutAlign - public RunGradleCheckLibTester(gitRepoUrl, gitReference){ + public RunGradleCheckLibTester(gitRepoUrl, gitReference, bwcCheckoutAlign){ this.gitRepoUrl = gitRepoUrl this.gitReference = gitReference + this.bwcCheckoutAlign = bwcCheckoutAlign } void configure(helper, binding) { @@ -27,6 +29,7 @@ class RunGradleCheckLibTester extends LibFunctionTester { void parameterInvariantsAssertions(call) { assertThat(call.args.gitRepoUrl.first(), notNullValue()) assertThat(call.args.gitReference.first(), notNullValue()) + assertThat(call.args.bwcCheckoutAlign.first(), notNullValue()) } boolean expectedParametersMatcher(call) { diff --git a/vars/runGradleCheck.groovy b/vars/runGradleCheck.groovy index f471eb92..19882f41 100644 --- a/vars/runGradleCheck.groovy +++ b/vars/runGradleCheck.groovy @@ -10,9 +10,16 @@ void call(Map args = [:]) { def lib = library(identifier: 'jenkins@6.5.2', retriever: legacySCM(scm)) def git_repo_url = args.gitRepoUrl ?: 'null' def git_reference = args.gitReference ?: 'null' + def bwc_checkout_align = args.bwcCheckoutAlign ?: 'false' + def bwc_checkout_align_param = '' println("Git Repo: ${git_repo_url}") println("Git Reference: ${git_reference}") + println("Bwc Checkout Align: ${bwc_checkout_align}") + + if (Boolean.parseBoolean(bwc_checkout_align)) { + bwc_checkout_align_param = '-Dbwc.checkout.align=true' + } if (git_repo_url.equals('null') || git_reference.equals('null')) { println("No git repo url or git reference to checkout the commit, exit 1") @@ -71,7 +78,7 @@ void call(Map args = [:]) { echo "Start gradlecheck" GRADLE_CHECK_STATUS=0 - ./gradlew clean && ./gradlew check -Dtests.coverage=true --no-daemon --no-scan || GRADLE_CHECK_STATUS=1 + ./gradlew clean && ./gradlew check -Dtests.coverage=true ${bwc_checkout_align_param} --no-daemon --no-scan || GRADLE_CHECK_STATUS=1 if [ "\$GRADLE_CHECK_STATUS" != 0 ]; then echo Gradle Check Failed!