QA/TestOps
[katalon] Jenkins Integration하기
킨글
2020. 6. 1. 17:22
jenkins pipleline 코드입니다.
jenkins를 활용해서 원격으로 실행시키거나 형상관리할 때 효율적으로 사용할 수 있겠죠?
import hudson.tasks.test.AbstractTestResultAction
import hudson.model.Actionable
def pipeName = "${JOB_NAME}"
node {
def Test_Env = ""
def jobname = "${env.JOB_NAME}"
def katalon_HOME = "D:\\Katalon_Studio_Engine_Windows_64-7.5.1"
def katalon_PJT = "$WORKSPACE" + "\\insight_automation_test.prj"
def katalon_Testsuite = "Test Suites/Screening/AD_610_001_Result_PT_TopMenu1"
def katalon_Key = "KATALON_API_KEY"
// def katalon_cmd = "$katalon_HOME" + "\\katalonc -noSplash -runMode=console -projectPath=\"" + "$katalon_PJT" + "\" -retry=0 -testSuiteCollectionPath=\"" + "$katalon_Testsuite" + "\" -apiKey=" + "$katalon_Key"
def katalon_cmd = "$katalon_HOME" + "\\katalonc -noSplash -runMode=console -projectPath=\"" + "$katalon_PJT" + "\" -retry=0 -testSuitePath=\""+"$katalon_Testsuite" + "\" -executionProfile=\"Production_ejy\" -browserType=\"Chrome\" -apiKey=" + "$katalon_Key"
def junit_report_path = "Reports/**/JUnit_Report.xml"
def report_url_format = "http://localhost:8080/jenkins/job/job_name/test_results_analyzer/"
def report_url = report_url_format.replaceAll(/job_name/, "${jobname}")
if (jobname ==~ /.*QA.*/) {
Test_Env = "QA"
}
else if (jobname ==~ /.*ST.*/) {
Test_Env = "Staging"
}
else if (jobname ==~ /.*Prod.*/) {
Test_Env = "Production"
}
else {
Test_Env = "test"
}
def subject = "Test Environment : ${Test_Env}"
try {
stage('Prepare Tests'){
// 빌드 중 중단될 경우 프로세스가 남아있어 workspace 삭제가 안됨. 남아있는 프로세스를 강제로 종료하도록 함.
// java 프로세스 확인 > 있으면 kill
ProcessINFO = bat(label: 'get pid', returnStdout: true, script:"@tasklist /FI \"ImageName eq java.exe\" /FI \"WindowTitle ne Tomcat\" /FO LIST")
if (ProcessINFO =~ "정보: 실행 중인 작업 중 지정된 조건에 일치하는 작업이 없습니다.")
{
println "Java process does not exist"
}
else
{
Plist = ProcessINFO.readLines()
PID = Plist[2].replace("PID:", "")
PID = PID.replaceAll("\\s", "")
println "PID: " + "${PID}" +"\n"
bat "taskkill /F /pid ${PID}"
}
// katalon 프로세스 확인 > 있으면 kill
//bat "taskkill /F /FI \"imagename eq katalon.exe\""
// chrome 프로세스 확인 > 있으면 kill
//bat "taskkill /F /FI \"imagename eq chrome.exe\""
// chromedriver 프로세스 확인 > 있으면 kill
//bat "taskkill /F /FI \"imagename eq chromedriver.exe\""
sleep(time:10,unit:"SECONDS")
// workspace clean
cleanWs()
}
}catch (e) {
error "Prepare Fail"
}
try {
stage('Source Checkout'){
// credentialsId는 Jenkins에서 발급
git branch: 'master', credentialsId: 'ejy1024', url: 'https://test@bitbucket.org/test/insight_automation.git'
}
}catch (e) {
error "Checkout Fail"
}
try {
stage('Run Tests'){
bat "${katalon_cmd}"
}
}catch (e) {
if (currentBuild.result == 'FAILURE') {
error "Abort Test"
}
}
try {
stage('Generate Report'){
junit "${junit_report_path}"
}
}catch (e) {
error "Generate report Fail"
}
}
Jenkins를 원격으로 실행하는것도 좋은데, 결과를 Mattermost로 받아보고 싶다면?!