forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runGradleCheck.groovy
84 lines (66 loc) · 3.2 KB
/
runGradleCheck.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* 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 = [:]) {
def lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))
def git_repo_url = args.gitRepoUrl ?: 'null'
def git_reference = args.gitReference ?: 'null'
println("Git Repo: ${git_repo_url}")
println("Git Reference: ${git_reference}")
if (git_repo_url.equals('null') || git_reference.equals('null')) {
println("No git repo url or git reference to checkout the commit, exit 1")
System.exit(1)
}
else {
withCredentials([
usernamePassword(credentialsId: "jenkins-gradle-check-s3-aws-credentials", usernameVariable: 'amazon_s3_access_key', passwordVariable: 'amazon_s3_secret_key'),
usernamePassword(credentialsId: "jenkins-gradle-check-s3-aws-resources", usernameVariable: 'amazon_s3_base_path', passwordVariable: 'amazon_s3_bucket')]) {
sh """
#!/bin/bash
set -e
set +x
echo "Git clone: ${git_repo_url} with ref: ${git_reference}"
rm -rf search
git clone ${git_repo_url} search
cd search/
git checkout -f ${git_reference}
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
echo "Check existing dockercontainer"
docker ps -a
docker stop `docker ps -qa` > /dev/null 2>&1 || echo
docker rm `docker ps -qa` > /dev/null 2>&1 || echo
echo "Stop existing dockercontainer"
docker ps -a
echo "Check docker-compose version"
docker-compose version
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 --no-daemon --no-scan || GRADLE_CHECK_STATUS=1
if [ "\$GRADLE_CHECK_STATUS" != 0 ]; then
echo Gradle Check Failed!
exit 1
fi
"""
}
}
}