Skip to content

Commit

Permalink
Cleanup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anupama2501 committed Jan 3, 2025
1 parent 0b908ac commit c44527c
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions tests/v2/validation/pipeline/Jenkinsfile.release.upgrade.local
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ node {
def testContainer = "${job_name}${env.BUILD_NUMBER}_test"
def buildTestContainer = "${job_name}${env.BUILD_NUMBER}-buildtest"
def configGeneratorContainer = "${job_name}${env.BUILD_NUMBER}_generator"
def cleanupContainer = "${job_name}${env.BUILD_NUMBER}_cleanup"
def cleanupTestContainer = "${job_name}${env.BUILD_NUMBER}_cleanup"

def validationVolume = "ValidationSharedVolume-${job_name}${env.BUILD_NUMBER}"

Expand Down Expand Up @@ -64,12 +64,6 @@ node {
timeout = "${env.TIMEOUT}"
}



def date = sh(script: "date +%Y-%m-%d", returnStdout: true).trim()
env.TEST_RUN_NAME = "${env.TEST_RUN_NAME ?: ''}${date}"
echo "Updated TEST_RUN_NAME: ${env.TEST_RUN_NAME}"

def cleanup = env.RANCHER_CLEANUP.toLowerCase()

def localConfigFileName = ""
Expand Down Expand Up @@ -173,6 +167,12 @@ node {
writeFile file: AWS_SSH_KEY_NAME, text: decoded
}
}

def date = sh(script: "date +%Y-%m-%d", returnStdout: true).trim()
if ("${env.TEST_RUN_NAME}" != "null" && "${env.TEST_RUN_NAME}" != ""){
env.TEST_RUN_NAME = "${env.TEST_RUN_NAME ?: ''}${date}"
echo "Updated TEST_RUN_NAME: ${env.TEST_RUN_NAME}"
}

scriptPath = "./rancher/tests/v2/validation/pipeline/scripts/rancher_k8s_version.sh"

Expand Down Expand Up @@ -240,16 +240,6 @@ node {
sh "docker run -v ${validationVolume}:/root --name ${buildTestContainer} -t --env-file ${envFile} " +
"${imageName} sh -c \"${workPath}pipeline/scripts/setup_environment.sh;${workPath}pipeline/scripts/build_qase_auto_testrun.sh\""

sh "docker cp ${buildTestContainer}:${workPath}${qaseRun} ./"
sh "./${qaseRun} --startRun=true"

if ("${env.QASE_TEST_RUN_ID}" == "null" || "${env.QASE_TEST_RUN_ID}" == "") {
echo "Getting the qase testID"
env.QASE_TEST_RUN_ID = sh (
script: "./yq '.id' ./${testRunConfig}",
returnStdout: true
).trim()
}
} catch(err) {
sh "docker stop ${buildTestContainer}"
sh "docker rm -v ${buildTestContainer}"
Expand Down Expand Up @@ -377,7 +367,16 @@ node {
).trim()

sh "docker cp ${buildTestContainer}:${workPath}${qaseRun} ./"

sh "./${qaseRun} --startRun=true"


if ("${env.QASE_TEST_RUN_ID}" == "null" || "${env.QASE_TEST_RUN_ID}" == "") {
echo "Getting the qase testID"
env.QASE_TEST_RUN_ID = sh (
script: "./yq '.id' ./${testRunConfig}",
returnStdout: true
).trim()
}
def goValidationParams = [
string(name: 'TIMEOUT', value: "30m"),
text(name: 'CONFIG', value: configYaml),
Expand All @@ -400,7 +399,6 @@ node {
} catch(err) {
echo "Pre upgrade tests had failures: " + err
}
sh "./${qaseRun} --startRun=false"
}

stage('Upgrade local cluster version') {
Expand All @@ -418,10 +416,6 @@ node {
returnStdout: true
).trim()

echo "Getting the test run ID in upgrade local cluster"

sh "docker cp ${buildTestContainer}:${workPath}${qaseRun} ./"

def goValidationParams = [
string(name: 'TIMEOUT', value: "2h"),
text(name: 'CONFIG', value: configYaml),
Expand All @@ -438,7 +432,6 @@ node {
} catch(err) {
echo "Kubernetes upgrade tests had failures: " + err
}
sh "./${qaseRun} --startRun=false"
}
stage('Run postupgrade checks') {
try {
Expand All @@ -459,10 +452,6 @@ node {
returnStdout: true
).trim()

echo "Getting the test run ID in post upgrade checks"

sh "docker cp ${buildTestContainer}:${workPath}${qaseRun} ./"

def goValidationParams = [
string(name: 'TIMEOUT', value: "30m"),
text(name: 'CONFIG', value: configYaml),
Expand All @@ -487,34 +476,37 @@ node {
}
sh "./${qaseRun} --startRun=false"
}
stage('Delete Rancher and resources') {
stage('Delete Rancher and resources') {
if (cleanup.toBoolean()) {
try{
sh 'echo Cleanup is enabled'

sh "docker run --volumes-from ${buildTestContainer} --name ${cleanupContainer} -t --env-file ${envFile} " +
sh "docker run --volumes-from ${buildTestContainer} --name ${cleanupTestContainer} -t --env-file ${envFile} " +
"${imageName} sh -c \"${workPath}pipeline/scripts/rancher_cleanup.sh\""

sh "docker stop ${cleanupContainer}"
sh "docker rm -v ${cleanupContainer}"
} catch(err){
echo "Cleanup had failures: " + err

if (sh(script: "docker inspect ${containerName} > /dev/null 2>&1 && echo 'exists' || echo 'not found'", returnStdout: true).trim() == 'exists') {
sh "docker stop ${cleanupTestContainer}"
sh "docker rm -v ${cleanupTestContainer}"
} else {
echo "Container ${cleanupTestContainer} not found, skipping cleanup."
}

sh "docker rmi -f ${imageName}"
}
} else {
sh 'echo Cleanup is disabled'
}
}
stage('Test Report') {
sh "docker stop ${testContainer}"
sh "docker rm -v ${testContainer}"
sh "docker stop ${buildTestContainer}"
sh "docker rm -v ${buildTestContainer}"

sh "docker stop ${configGeneratorContainer}"
sh "docker rm -v ${configGeneratorContainer}"

if (cleanup.toBoolean()) {
sh "docker stop ${cleanupContainer}"
sh "docker rm -v ${cleanupContainer}"
}

sh "docker rmi -f ${imageName}"
}
Expand All @@ -525,13 +517,18 @@ node {
try {
sh 'echo Cleanup is enabled'

sh "docker run --volumes-from ${buildTestContainer} --name ${cleanupContainer} -t --env-file ${envFile} " +
"${imageName} sh -c \"${workPath}pipeline/scripts/rancher_cleanup.sh\""
sh "docker run --volumes-from ${buildTestContainer} --name ${cleanupTestContainer} -t --env-file ${envFile} " +
"${golangImageName} sh -c \"${workPath}pipeline/scripts/rancher_cleanup.sh\""

sh "docker stop ${cleanupContainer}"
sh "docker rm -v ${cleanupContainer}"
} catch(error) {
echo "Cleanup had failures: " + error

if (sh(script: "docker inspect ${containerName} > /dev/null 2>&1 && echo 'exists' || echo 'not found'", returnStdout: true).trim() == 'exists') {
sh "docker stop ${cleanupTestContainer}"
sh "docker rm -v ${cleanupTestContainer}"
} else {
echo "Container ${cleanupTestContainer} not found, skipping cleanup."
}
}
} else {
sh 'echo Cleanup is disabled'
Expand Down

0 comments on commit c44527c

Please sign in to comment.