Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger PR builds #4795

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 136 additions & 75 deletions buildenv/jenkins/jck_sync
Original file line number Diff line number Diff line change
@@ -1,95 +1,156 @@
#!groovy
def PR_NUMBER = 0
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved

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'
}

}
if (params.LABEL !="") {
LABEL = params.LABEL
} else {
LABEL = "ci.role.test&&hw.arch.x86&&sw.os.linux"
}
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
node(LABEL) {
println "LABEL: ${LABEL}"
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
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}": ""
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')
]) {
def currentDirectory = sh(script: 'pwd', returnStdout: true).trim()
dir("${currentDirectory}/aqa-tests/jck/jck-semiauto-updater") {
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
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)
def scriptOutput = readFile(tempOutputFile).trim()
echo ("JCKUpdater script output:")
echo scriptOutput
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
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 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}")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When triggering the PR build, CUSTOMIZED_SDK_URL and LABEL should not be passed to PR build

Copy link
Contributor Author

@KapilPowar KapilPowar Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not passing CUSTOMIZED_SDK_URL and LABEL. To make sure job runs without CUSTOMIZED_SDK_URL need to change SDK_RESOURCE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • No, SDK_RESOURCE = releases is not correct. I meant if CUSTOMIZED_SDK_URL is pointing to a specific URL, then we cannot pass the parent CUSTOMIZED_SDK_URL to the child jobs as the child jobs can run on multiple platforms. The best way to do it is to add a comment in the Jenkins job config to warn the users. Please remove the settings of SDK_RESOURCE and CUSTOMIZED_SDK_URL.
  • Also, to simplify this, I think we should not use LABEL for two separate purposes. We should rename the LABEL to SYNC_LABEL. See line 6 - 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added NOTE to jenkins job config for CUSTOMIZED_SDK_URL.
NOTE: Using specific URL may create issues with child jobs doing sanity test on different platforms.

}
}
}
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 (param.key == "SDK_RESOURCE") {
CHILD_PARAMS << string(name: param.key, value: "releases")
} else if (param.key == "CUSTOMIZED_SDK_URL") {
CHILD_PARAMS << string(name: param.key, value: "")
} else if (param.key == "LABEL") {
CHILD_PARAMS << string(name: param.key, value: "")
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
} 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) {
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}"
GET_SH_CMD = "./get.sh -s `pwd`/.. -p x86-64_linux -r ${SDK_RESOURCE} ${JDK_VERSION_OPTION} ${JDK_IMPL_OPTION} ${CUSTOMIZED_SDK_URL_OPTION} --clone_openj9 false"
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
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}"
echo ("${comment}")
KapilPowar marked this conversation as resolved.
Show resolved Hide resolved
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} ")
}
}
}