엄지월드

Katalon&Mattermost&Bitbucket&Jenkins Integration 하기 본문

QA/TestOps

Katalon&Mattermost&Bitbucket&Jenkins Integration 하기

킨글 2020. 5. 28. 09:00
반응형

- jenkins 설치(D:\apache-tomcat-8.5.45\webapps에 war 파일을 놓으면, startup.bat 파일 실행 시 자동으로 설치됨)

- Mattermost Notification Plugin 설치

- Mattermost Plugin 설치 후, (Jenkins 관리) > (시스템 설정)에서 하단에 위치한 Global Mattermost Notifier Settings를 설정해줍니다. 
EndPoint : mattermost 주소
Channel : mattermost 채널

BUild Server URL : 자신의 jenkins 주소

- jenkins에서 credencial 등록(http://localhost:8080/jenkins/credentials/store/system/)

- katalon report plugin 다운로드

https://store.katalon.com/product/59/Basic-Report

- pipeline 등록 후 Build

import hudson.tasks.test.AbstractTestResultAction
import hudson.model.Actionable

def pipeName = "${JOB_NAME}"
@NonCPS
def getTestSummary = { ->
    def testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
    def summary = ""

    if (testResultAction != null) {
        def total = testResultAction.getTotalCount()
        def failed = testResultAction.getFailCount()
        def skipped = testResultAction.getSkipCount()

        summary = summary + (pipeName+" TOTAL: " + total)
		summary = summary + ("\n\t - PASS : " + (total - failed - skipped))
        summary = summary + ("\n\t - FAIL : " + failed)
        summary = summary + ("\n\t - SKIP : " + skipped)
    } else {
        summary = "No tests found"
    }
    return summary
}

node {

	def Test_Env = ""
	def mattermost_channel = "#INSIGHT_AUTOMATION"
	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"
    }

  //color code : RED 00FF00  GREEN #FF0000
    mattermostSend(channel : "${mattermost_channel}", color : '#FF0000', message : '====== '+pipeName+' UI 테스트 시작 ======')
	//mattermostSend(channel : "${mattermost_channel}", message : "${subject}")

    try {
	    stage('Source Checkout'){
	       // mattermostSend(channel : "${mattermost_channel}", message: "1. "+pipeName+" Source Checkout")
          // credentialsId는 Jenkins에서 발급
		    git branch: 'master', credentialsId: 'ejy1024', url: 'https://test@bitbucket.org/test/insight_automation.git'
           // mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Completed")
	    }
    }
    catch (e) {
        mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Uncompleted")
	    mattermostSend(channel : "${mattermost_channel}", color : '00FF00', message: " !!!  "+pipeName+" 소스 체크아웃 실패 !!!")
		error "Checkout Fail"
    }


    try {
	    stage('Run Tests'){
	       // mattermostSend(channel : "${mattermost_channel}", message: "2. "+pipeName+" Run Tests")
			bat "${katalon_cmd}"
		   // mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Completed")
	    }
    }
    catch (e) {
	    if (currentBuild.result == 'FAILURE') {
			mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Uncompleted")
			mattermostSend(channel : "${mattermost_channel}", color : '00FF00', message: " !!! "+pipeName+" UI 테스트 중단 !!!")
			error "Abort Test"
			}
        else {
			// mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Completed")
			}
    }

    try {
	    stage('Generate Report'){
	       //mattermostSend(channel : "${mattermost_channel}", message: "3. "+pipeName+" Generate Report")
			junit "${junit_report_path}"
		   //mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Completed")
	    }
    }
    catch (e) {
        mattermostSend(channel : "${mattermost_channel}", message: "\t ▷▷▷ Uncompleted")
	    mattermostSend(channel : "${mattermost_channel}", color : '00FF00', message: " !!! "+pipeName+" 리포트 생성 실패 !!!")
	    error "Generate report Fail"
    }
    
	def testSummary = getTestSummary()

    // mattermostSend(channel : "${mattermost_channel}", message : '-----------------------------')
    mattermostSend(channel : "${mattermost_channel}", message : "[ Test Result ] \n\t ${testSummary}" )
    //mattermostSend(channel : "${mattermost_channel}", message : "[ Test Report ] \n\t ${report_url}")
    // mattermostSend(channel : "${mattermost_channel}", color : '#FF0000', message : '====== '+pipeName+' UI 테스트 종료 ======')

}

 

 

- 계속 Build 하면서 ScriptApproval을 계속 진행합니다. (http://localhost:8080/jenkins/scriptApproval/)

(다 하니 5개까지 담기네요..)

- 계속 돌리니 성공!

 

 

<광고 한번씩 클릭해주시면 저에게 큰 힘이 됩니다 😃>

 

'QA > TestOps' 카테고리의 다른 글

jenkins 원격 빌드  (0) 2021.03.25
Jenkins 업데이트 방법  (0) 2020.07.10
[katalon] Jenkins Integration하기  (0) 2020.06.01
jenkins를 통해 Katalon Runtime Engine실행 방법  (0) 2020.05.27
Comments