Skip to content

Commit

Permalink
Trigger PR builds (#4795)
Browse files Browse the repository at this point in the history
* Running Grinder sanity test

* Review changes

* Review Changes

* Review changes

---------

Co-authored-by: Kapil Powar <[email protected]>
  • Loading branch information
KapilPowar and kapilpowar17 authored Oct 10, 2023
1 parent 4163905 commit 3548555
Showing 1 changed file with 125 additions and 75 deletions.
200 changes: 125 additions & 75 deletions buildenv/jenkins/jck_sync
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,144 @@

timestamps{
stage('Setup') {
if (params.LABEL !="") {
LABEL = params.LABEL
} else {
LABEL = "ci.role.test&&hw.arch.x86&&sw.os.linux"
}
node(LABEL) {
println "LABEL: ${LABEL}"
echo "clone the SCM GIT repo"
try {
def gitConfig = scm.getUserRemoteConfigs().get(0)
checkout scm: [$class: 'GitSCM',
branches: [[name: "${scm.branches[0].name}"]],
extensions: [
[$class: 'CleanBeforeCheckout'],
[$class: 'CloneOption'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'aqa-tests']],
userRemoteConfigs: [[url: "${gitConfig.getUrl()}"]]
]

syncJckMaterial()

} catch (Exception e) {
println("Exception: " + e.toString())
// build result may not be updated correctly at the moment (see https://issues.jenkins.io/browse/JENKINS-56402)
// if there is an exception, set currentBuild.result to ABORTED/FAILURE
if (e.toString().contains("FlowInterruptedException")) {
currentBuild.result = 'ABORTED'
} else {
currentBuild.result = 'FAILURE'
}

}
def SYNC_LABEL = params.SYNC_LABEL ?: "ci.role.test&&hw.arch.x86&&sw.os.linux"
println "SYNC_LABEL: ${SYNC_LABEL}"
node(SYNC_LABEL) {
echo ("clone the SCM GIT repo")
try {
def gitConfig = scm.getUserRemoteConfigs().get(0)
checkout scm: [$class: 'GitSCM',
branches: [[name: "${scm.branches[0].name}"]],
extensions: [
[$class: 'CleanBeforeCheckout'],
[$class: 'CloneOption'],
[$class: 'RelativeTargetDirectory', relativeTargetDir: 'aqa-tests']],
userRemoteConfigs: [[url: "${gitConfig.getUrl()}"]]
]
syncJckMaterial()
} catch (Exception e) {
// build result may not be updated correctly at the moment (see https://issues.jenkins.io/browse/JENKINS-56402)
// if there is an exception, set currentBuild.result to ABORTED/FAILURE
if (e.toString().contains("The job is completed without further action")){
println("JCKUpdater script returned exit code 2, as no new update available. The job is completed without further action.")
currentBuild.result = "SUCCESS"
} else if (e.toString().contains("FlowInterruptedException")) {
currentBuild.result = 'ABORTED'
println("Exception: " + e.toString())
} else {
currentBuild.result = 'FAILURE'
println("Exception: " + e.toString())
}
}
}
}
}

def syncJckMaterial(){
echo "Starting script to sync JCK materials ....."
def JCK_VERSION = params.JDK_VERSION ? "-j ${params.JDK_VERSION}": ""
def JCK_GIT_BRANCH = params.JCK_GIT_BRANCH ? "-gb ${params.JCK_GIT_BRANCH}": ""
def ARTIFACTORY_URL = params.ARTIFACTORY_URL ? "-au ${params.ARTIFACTORY_URL}": ""
def JCK_GIT_REPO = params.JCK_GIT_REPO ? "-repo ${params.JCK_GIT_REPO}": ""
stage('JCKUpdater') {
script {
getJavaSDK()
echo ("Starting script to sync JCK materials .....")
def JCK_VERSION = params.JDK_VERSION ? "-j ${params.JDK_VERSION}": ""
def JCK_GIT_BRANCH = params.JCK_GIT_BRANCH ? "-gb ${params.JCK_GIT_BRANCH}": ""
def ARTIFACTORY_URL = params.ARTIFACTORY_URL ? "-au ${params.ARTIFACTORY_URL}": ""
def JCK_GIT_REPO = params.JCK_GIT_REPO ? "-repo ${params.JCK_GIT_REPO}": ""
def PR_NUMBER = 0
stage('JCKUpdater') {
getJavaSDK()

withCredentials([
usernamePassword(credentialsId: "${params.ARTIFACTORY_CREDENTIALS}",
usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_CREDENTIALS'),
string(credentialsId: "${params.GIT_CREDENTIALS}",variable: 'GIT_CREDENTIALS')
]) {
def currentDirectory = sh(script: 'pwd', returnStdout: true).trim()
dir("${currentDirectory}/aqa-tests/jck/jck-semiauto-updater") {
sshagent(credentials:["${params.USER_CREDENTIALS_ID}"], ignoreMissing: true){
def SCRIPT = "./jckupdater.sh ${JCK_VERSION} -at ${ARTIFACTORY_CREDENTIALS} ${JCK_GIT_REPO} -gt ${GIT_CREDENTIALS} ${ARTIFACTORY_URL} ${JCK_GIT_BRANCH}"
echo "${SCRIPT}"
def EXITCODE = sh(script: "${SCRIPT}", returnStatus: true)
echo "EXITCODE= ${EXITCODE}"
if (EXITCODE == 2) {
echo "Script returned exit code 2, No new update available. Marking the job as SUCCESS. "
} else if (EXITCODE == 0) {
echo "Script returned exit code 0, new update is available and PR is created."
} else {
error("script failed with exit code ${EXITCODE}")
}
}
}
withCredentials([
usernamePassword(credentialsId: "${params.ARTIFACTORY_CREDENTIALS}",
usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_CREDENTIALS'),
string(credentialsId: "${params.GIT_CREDENTIALS}",variable: 'GIT_CREDENTIALS')
]) {
dir("${WORKSPACE}/aqa-tests/jck/jck-semiauto-updater"){
sshagent(credentials:["${params.USER_CREDENTIALS_ID}"], ignoreMissing: true){
def SCRIPT = "./jckupdater.sh ${JCK_VERSION} -at \"\$ARTIFACTORY_CREDENTIALS\" ${JCK_GIT_REPO} -gt \"\$GIT_CREDENTIALS\" ${ARTIFACTORY_URL} ${JCK_GIT_BRANCH} "
def tempOutputFile = "temp_output.txt"
def EXITCODE = sh(script: "${SCRIPT} > ${tempOutputFile}", returnStatus: true)
if (EXITCODE == 2) {
error ("JCKUpdater script returned exit code 2, as no new update available. The job is completed without further action.")
currentBuild.result = "SUCCESS"
} else if (EXITCODE == 0) {
echo ("Script returned exit code 0, new update is available and PR is created.")
def scriptOutput = readFile(tempOutputFile).trim()
echo ("JCKUpdater script output:")
echo scriptOutput
def matcher = (scriptOutput =~ /PR_NUMBER=\s*(\d+)/)
PR_NUMBER = matcher ? matcher[0][1] : null
if (PR_NUMBER == null || PR_NUMBER == 0) {
error ("PR_NUMBER not found in script output.")
} else {
echo ("PR created with number : ${PR_NUMBER}")
}
} else {
error ("script failed with exit code ${EXITCODE}")
}
}
}
}
}
stage('Test') {
def CHILD_JOB_NAME="Grinder_JCK"
def BUILD_URL="${JENKINS_URL}job/${CHILD_JOB_NAME}/"
def CHILD_PARAMS = []
// loop through all the params and change the parameters if needed
params.each { param ->
def value = param.value.toString()
if (param.key == "JCK_GIT_BRANCH") {
if (value.trim() == ""){
value = "autoBranch" //default branch name given in JCKUpdater.sh script
}
CHILD_PARAMS << string(name: param.key, value: value)
} else {
if (value == "true" || value == "false") {
CHILD_PARAMS << booleanParam(name: param.key, value: value.toBoolean())
} else {
CHILD_PARAMS << string(name: param.key, value: value)
}
}
}
def BUILD_INFO = build job: CHILD_JOB_NAME, parameters: CHILD_PARAMS
def COMMENT="Job [#${BUILD_INFO.number}](${BUILD_URL}${BUILD_INFO.number}) completed with status: ${BUILD_INFO.result}"
createComment(COMMENT,PR_NUMBER)
}
}

//Download JAVA SDK
def getJavaSDK(){

JDK_VERSION_OPTION = params.JDK_VERSION ? "-j ${params.JDK_VERSION}" : ""
JDK_IMPL_OPTION = params.JDK_IMPL ? "-i ${params.JDK_IMPL}" : ""
CUSTOMIZED_SDK_URL_OPTION = "-c ${params.CUSTOMIZED_SDK_URL}"
CLONE_OPENJ9_OPTION = (params.CLONE_OPENJ9) ? "--clone_openj9 ${params.CLONE_OPENJ9}" : ""

GET_SH_CMD = "./get.sh -s `pwd`/.. -p $PLATFORM -r ${SDK_RESOURCE} ${JDK_VERSION_OPTION} ${JDK_IMPL_OPTION} ${CUSTOMIZED_SDK_URL_OPTION} ${CLONE_OPENJ9_OPTION}"
dir("${WORKSPACE}/aqa-tests") {
if (params.CUSTOMIZED_SDK_URL_CREDENTIAL_ID) {
def JDK_VERSION_OPTION = params.JDK_VERSION ? "-j ${params.JDK_VERSION}" : ""
def CUSTOMIZED_SDK_URL_OPTION = "-c ${params.CUSTOMIZED_SDK_URL}"
def CLONE_OPENJ9_OPTION = "--clone_openj9 false"
def PLATFORM_OPTION = "-p x86-64_linux"
def GET_SH_CMD = "./get.sh -s `pwd`/.. ${PLATFORM_OPTION} ${JDK_VERSION_OPTION} ${CUSTOMIZED_SDK_URL_OPTION} ${CLONE_OPENJ9_OPTION} "
dir("${WORKSPACE}/aqa-tests") {
if (params.CUSTOMIZED_SDK_URL_CREDENTIAL_ID) {
withCredentials([usernamePassword(credentialsId: "${params.CUSTOMIZED_SDK_URL_CREDENTIAL_ID}", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "$GET_SH_CMD"
}
} else {
sh "$GET_SH_CMD"
}
sh "$GET_SH_CMD"
}
} else {
sh "$GET_SH_CMD"
}
}
}

def createComment(comment,number) {
withCredentials([
string(credentialsId: "${params.GIT_CREDENTIALS}",variable: 'GIT_CREDENTIALS')
]) {
def DOMAIN = params.JCK_GIT_REPO.split(/[@:]/)
def REPO = DOMAIN[2].split('\\.')
def COMMENT_URL="https://${DOMAIN[1]}/api/v3/repos/${REPO[0]}/issues/${number}/comments"
def PR_URL="https://${DOMAIN[1]}/${REPO[0]}/pull/${number}"
def CURL_COMMAND = """
curl -X POST -H "Authorization: token \"\$GIT_CREDENTIALS\"" \\
-d '{
"body":"${comment}"
}' "$COMMENT_URL"
"""
def STATUS = sh(script: CURL_COMMAND, returnStatus: true, returnStdout: true)
if (STATUS == 0) {
echo ("Comment added successfully to PR ${PR_URL} ")
} else {
error ("Failed to add a comment to PR ${PR_URL} ")
}
}
}

0 comments on commit 3548555

Please sign in to comment.