Jenkins Pipeline Script 예시

이 페이지에서

Jenkins 파이프라인에서 Apptest.ai Ptero 테스트 실행 → 상태 조회 → 결과 수집 → JUnit 게시까지 자동화할 수 있습니다.

스크립트 입력 정보

keytypedescription
userNamestringApptest.ai Ptero (홈페이지) 로그인 ID
accessKeystringApptest.ai Ptero (홈페이지) → Edit Profile > Access Key
pidint테스트를 진행할 Project ID
testSuiteIdintProject → Test Suites → Test Suite ID
osstring테스트를 진행할 Device OS 플랫폼 (ANDROID | iOS)
devicestringProject → Device category
→ Device key, 또는 “random_device”
random_device 규칙:
① Project에 설정된 디바이스가 없는 경우
→ 사용 가능한 모든 디바이스 중 무작위 1개 선택
② Project에 설정된 디바이스가 있는 경우
→ 설정된 디바이스 중 무작위 1개 선택
sourceTypestring실행할 앱 지정 방식 (app_id | file)
appFilePathstring앱 파일 경로 (apk, apks, xapk, ipa 확장자만 허용)
appDownloadUrlstring앱 다운로드 URL (http://, https:// 프로토콜 포함 필수)
appIdstring테스트 대상 앱 ID
– Android: package name
– iOS: bundle ID

주의
app_id, app_file, app_download_url, source_type 중 하나만 선택해서 전달해야 합니다.
2개 이상 전달하면 Value Error가 발생합니다.
자세한 내용은 테스트 생성을 참고해 주세요.

기본 설정값 (수정 불필요)

keytypedescription
apiHoststringAPI Host 주소
runTestUrlstring테스트 실행 API URL
testStatusCheckUrlstring테스트 상태 확인 API URL
testSuiteRunIdinttest_suite_run_id.
테스트 완료 시 Script 내부에서 자동 할당됨

Pipeline Script 예시

Groovy
import groovy.json.*

node {
   def apiHost = "https://app.apptest.ai/api"
   def runTestUrl
   def testStatusCheckUrl
   def testSuiteRunId
   
   def userName
   def accessKey
   def pid
   def testSuiteId
   def os
   def device
   def sourceType
   def appFile
   def appDownloadUrl
   def appId

   // Add to your Preparation Stage
   stage('Preparation') {
       echo "[ apptest.ai ] Current workspace : ${workspace}"
       
       userName = 'your_user_id'
       accessKey = 'your_access_key'
       pid = 9876      
       os = 'iOS'  // ANDROID | iOS
       testSuiteId = 112233
       device = 'random_device' // random_device or device key

       // select one of the sourceType, appFile, appDownloadUrl, appId and change your form data
       sourceType = "file" // file | app_id

       // appDownloadUrl = "https://app.download.domain/download/path"

       // appFilePath = "/home/com.android.chrome.apk"
       // appFile = "@\"${appFilePath}\""

       // appId = "com.android.chrome" // ANDROID: package name, iOS: bundle name

       runTestUrl = "${apiHost}/openapi/v3/projects/${pid}/test-suite-runs"

       echo "[ apptest.ai ] Preparation successfully."
   }

   // apptest.ai Test run Stage
   stage('apptest.ai Test Run') {
       // Call apptest.ai's Test run API.
       runTestSuite = sh(returnStdout: true, script: "curl -X POST -u '${userName}:${accessKey}' -F 'source_type=${sourceType}' -F 'test_suite_id=${testSuiteId}' -F 'device=${device}' -F 'os=${os}' ${runTestUrl}").toString().trim()
       runTestSuiteResponse = new JsonSlurperClassic().parseText(runTestSuite)
       // Test run fail case
       if (runTestSuiteResponse.result != "success") {
           echo "[ apptest.ai ] Failed to run the test. ${runTestSuite}"
           runTestSuite = null
           runTestSuiteResponse = null
           error "FAIL"
       }

       testSuiteRunId = runTestSuiteResponse['data']['test_suite_run_id']
       runTestSuite = null
       runTestSuiteResponse = null

       echo "[ apptest.ai ] Test run successfully. (TestSuiteRun ID : ${testSuiteRunId})"
   }

   // Apptest.ai Test status check Stage
   stage('apptestai Test Status Check') {
       completeAll = false
       testResultXml = ''

       // Repeat until all tests are complete
       while(!completeAll) {
           sleep (time: 60, unit: "SECONDS")
           testStatusCheckUrl = "${apiHost}/openapi/v3/test-suite-runs/${testSuiteRunId}"
           getTestStatusCheck = sh(returnStdout: true, script: "curl -X GET -u '${userName}:${accessKey}' ${testStatusCheckUrl}").toString().trim()
           getTestStatusCheckResponse = new JsonSlurperClassic().parseText(getTestStatusCheck)

           if (getTestStatusCheckResponse.result != "success") {
               echo "[ apptest.ai ] Failed to get test status. ${getTestStatusCheck}"
               getTestStatusCheck = null
               getTestStatusCheckResponse = null
               error "FAIL"
           }

           testStatus = getTestStatusCheckResponse.data.status.toLowerCase()
           echo "[ apptest.ai ] test-suite-run ${testSuiteRunId} complete result : ${testStatus}"

           if (testStatus == 'complete') {
               testResultUrl = "${apiHost}/openapi/v3/test-suite-runs/${testSuiteRunId}/result?data_type=xml"
               getTestResult = sh(returnStdout: true, script: "curl -X GET -u '${userName}:${accessKey}' '${testResultUrl}'").toString().trim()
               getTestResultResponse = new JsonSlurperClassic().parseText(getTestResult)
               passCount = getTestStatusCheckResponse.data.status_detail.passed
               totalCount = getTestStatusCheckResponse.data.total_test_count
               testResultXml = getTestResultResponse.data.result_xml

               if (passCount != totalCount) {
                   echo "[ apptest.ai ] status_detail ${getTestStatusCheckResponse.data.status_detail}"
                   echo "[ apptest.ai ] Failed to get test result data. ${testResultXml}"
                   getTestResult = null
                   getTestResultResponse = null
                   error "FAIL"
               }

               echo "[ apptest.ai ] Test completed. test-suite-run id : ${testSuiteRunId}"
               getTestResult = null
               getTestResultResponse = null
               completeAll = true
           }
           getTestStatusCheck = null
           getTestStatusCheckResponse = null
       }
       echo "[ apptest.ai ] All tests are completed."
       echo "[ apptest.ai ] Test result data : ${testResultXml}"
   }

   // Write apptest.ai test result data to file Stage
   stage('Write Apptestai Test Result') {
       sh "mkdir -p tmp/"
       sh "echo -n '${testResultXml}' > tmp/TESTS-Apptestai.xml"
   }

   // JUnit Test Stage
   stage('jUnit Test') {
       junit 'tmp/TESTS-*.xml'
   }
}