lib = library(identifier: 'jenkins@1.1.2', retriever: modernSCM([ $class: 'GitSCMSource', remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git', ])) pipeline { agent { label AGENT_LABEL } options { timeout(time: 2, unit: 'HOURS') throttleJobProperty( categories: [], limitOneJobWithMatchingParams: false, maxConcurrentPerNode: 0, maxConcurrentTotal: 20, paramsToUseForLimit: '', throttleEnabled: true, throttleOption: 'project', ) } parameters { string( name: 'GIT_REPO_URL', description: 'OpenSearch core repository url on git, can be either the official upstream url or your fork url.', defaultValue: 'https://github.com/opensearch-project/OpenSearch.git', trim: true ) string( name: 'GIT_REFERENCE', description: 'Git branch, tag, commitid for reference to checkout commit of OpenSearch core before running the gradle check.', defaultValue: 'main', trim: true ) // Must use agent with 1 executor or gradle check will show a lot of java-related errors // The c524xlarge is the instance type that has the least amount of errors during gradle check // https://github.com/opensearch-project/OpenSearch/issues/1975 // // Update 20230724: Recent investigation shows gradle check is memory-bound thus switch to a new // runner of M58xlarge for more stable runs // https://github.com/opensearch-project/opensearch-ci/issues/321 choice( name: 'AGENT_LABEL', description: 'Choose which jenkins agent to run gradle check on', choices: ['Jenkins-Agent-Ubuntu2004-X64-M58xlarge-Single-Host', 'Jenkins-Agent-Windows2019-X64-C524xlarge-Single-Host', 'Jenkins-Agent-Ubuntu2004-X64-C524xlarge-Single-Host'], ) } triggers { GenericTrigger( genericVariables: [ [key: 'pr_from_sha', value: '$.pr_from_sha'], [key: 'pr_from_clone_url', value: '$.pr_from_clone_url'], [key: 'pr_to_clone_url', value: '$.pr_to_clone_url'], [key: 'pr_title', value: '$.pr_title'], [key: 'pr_number', value: '$.pr_number'] ], tokenCredentialId: 'jenkins-gradle-check-generic-webhook-token', causeString: 'Triggered by PR on OpenSearch core repository', printContributedVariables: false, printPostContent: false ) parameterizedCron ''' H 3 * * * %GIT_REFERENCE=main;AGENT_LABEL=Jenkins-Agent-Ubuntu2004-X64-M58xlarge-Single-Host H 6 * * * %GIT_REFERENCE=1.x;AGENT_LABEL=Jenkins-Agent-Ubuntu2004-X64-M58xlarge-Single-Host H 9 * * * %GIT_REFERENCE=2.x;AGENT_LABEL=Jenkins-Agent-Ubuntu2004-X64-M58xlarge-Single-Host ''' } environment { BUILD_CAUSE = currentBuild.getBuildCauses() } stages { stage('Run Gradle Check') { steps { script { sh """ set +x set -e JAVA_HOME_LIST=`env | grep JAVA | grep HOME` echo "JAVA_HOME_LIST \$JAVA_HOME_LIST" if [ -n "\$JAVA_HOME_LIST" ] && [ "\$JAVA_HOME_LIST" != "" ]; then for java_version in \$JAVA_HOME_LIST; do echo \$java_version java_path="`echo \$java_version | cut -d= -f2`/bin/java -version" eval \$java_path done else echo "Missing JAVA_HOME information in env vars, exit 1" exit 1 fi """ def agent_name_array = params.AGENT_LABEL.tokenize('-') def agent_name = agent_name_array[2] + " " + agent_name_array[4] def CREDENTIAL_ID = 'jenkins-production-dockerhub-credential-readonly' echo("Build Cause: ${BUILD_CAUSE}") withCredentials([usernamePassword(credentialsId: CREDENTIAL_ID, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { def dockerLogin = sh(returnStdout: true, script: "set +x && echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin").trim() if (!env.BUILD_CAUSE.contains('Started by user') && !env.BUILD_CAUSE.contains('Started by timer')) { def pr_url = "${pr_to_clone_url}".replace(".git", "/pull/${pr_number}") println("Triggered by GitHub: ${pr_to_clone_url}") if ("$pr_number" == "Null") { currentBuild.description = """runner: ${agent_name}
Others: ${pr_title}""" } else { currentBuild.description = """runner: ${agent_name}
PR #${pr_number}: ${pr_title}""" } runGradleCheck( gitRepoUrl: "${pr_from_clone_url}", gitReference: "${pr_from_sha}" ) } else { println("Triggered by User or Triggered by Timer") def repo_url = "${GIT_REPO_URL}".replace(".git", "/commit") currentBuild.description = """runner: ${agent_name}
git: ${GIT_REPO_URL}
ref: ${GIT_REFERENCE}""" runGradleCheck( gitRepoUrl: "${GIT_REPO_URL}", gitReference: "${GIT_REFERENCE}" ) } sh("docker logout") } } } post() { failure { archiveArtifacts artifacts: '**/build/heapdump/*.hprof', allowEmptyArchive: true } always { sh ("cp -v `find search/build/reports/jacoco/ -name '*.xml' | head -n 1` codeCoverage.xml || echo") junit allowEmptyResults: true, testResults: '**/build/test-results/**/*.xml' archiveArtifacts artifacts: 'codeCoverage.xml', onlyIfSuccessful: true script { sh("rm -rf *") postCleanup() } } } } } post() { always { script { postCleanup() sh "docker logout && docker image prune -f --all" } } } }