Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 4.13 KB | None | 0 0
  1. #!/usr/bin/env groovy
  2.  
  3. def call(String project, String env, String area, String feature, String suite) {
  4.  
  5.     def container = "${project}_${new Random().nextInt(100000)}"
  6.     def url = ""
  7.     def command = ""
  8.     def platform = ""
  9.     def chunks = 10
  10.    
  11.     switch (project) {          
  12.         case 'launcher':
  13.             url = "https://${(feature == "develop") ? "" : feature + "-"}launcher.${(env == "qa") ? "test" : ""}4game.com"
  14.             if(feature == "live")
  15.                 url = "https://launcher.${area}.4game.com"
  16.             command = "test:multiple:${(env == "qa") ? "qa" : "live"}"
  17.             chunks = "${(env == "qa") ? 10 : 4}"
  18.             platform = "${project}-${env}-${feature}-ru"
  19.             break
  20.         case 'web':
  21.             if(env == "qa")
  22.                 url = "https://${area}-www.test4game.com"
  23.             else url = "https://${feature}-${area}.4game.com"
  24.             if(env != "qa" && area == "br")
  25.                 url = "https://br.4game.com"
  26.             command = "test:multiple:web:${suite}"
  27.             chunks = "${(env == "qa") ? 20 : 4}"
  28.             platform = "${project}-${env}-${feature}-${area}"
  29.             break
  30.         case 'carrier':
  31.             url = "https://carrier.test4game.com"
  32.             "https://${(feature == "develop") ? "" : feature + "-"}carrier.${(env == "qa") ? "test" : ""}4game.com"
  33.             command = "test:multiple:${(env == "qa") ? "qa" : "live"}"
  34.             break
  35.     }
  36.    
  37.     try {
  38.         if(project != "web" && (project == "launcher" && feature == "develop" && env != "production")) {
  39.             sh script: "docker build tests -t ${container}"
  40.             sh script: "docker rmi docker-registry.inn.ru/forgame/4game-ui-tests:latest || true"
  41.             sh script: "docker tag ${container} docker-registry.inn.ru/forgame/4game-ui-tests:latest"
  42.             sh script: "docker push docker-registry.inn.ru/forgame/4game-ui-tests:latest"
  43.             sh script: "docker run --shm-size=4096M -e 'BASE_URL=${url}' -e 'PLATFORM=${platform}' -e 'CHUNKS=${chunks}' --name ${container} ${container} -c 'npm run ${command}'"
  44.  
  45.         }
  46.         else {
  47.             sh script: "docker run --shm-size=4096M -e 'BASE_URL=${url}' -e 'PLATFORM=${platform}' -e 'CHUNKS=${chunks}' --name ${container} docker-registry.inn.ru/forgame/4game-ui-tests:latest -c 'npm run ${command}'"
  48.         }
  49.       }
  50.     finally {
  51.         sh script: "docker cp ${container}:/app/output output_${container} || true"
  52.         sh script: "docker rm ${container} || true"
  53.         sh script: "docker rmi ${container} || true"
  54.        
  55.         sh script: "mkdir allure-results || true"
  56.         sh script: "find output_${container} -type f -name '*.xml' -exec cp -t allure-results '{}' \\; || true"
  57.         sh script: "find output_${container} -type f -name '*.png' -exec cp -t allure-results '{}' \\; || true"
  58.         sh script: "echo 'URL=${url}\r\nPROJECT=${project}\r\nENV=${env}\r\nFEATURE=${feature}\r\nAREA=${area}' > allure-results/environment.properties"
  59.    
  60.    
  61.         allure results: [[path: 'allure-report']]
  62.         slackNotify()
  63.         cleanWs()
  64.     }
  65. }
  66.  
  67. @NonCPS
  68. void slackNotify() {
  69.     String color
  70.     String channel = '#ui-tests-notify'
  71.     if(currentBuild.result == null) {
  72.         if(currentBuild.id == '1'){
  73.             color = 'blue'
  74.         }
  75.         else if(currentBuild.previousBuild.result == 'SUCCESS'){
  76.             color = 'good'
  77.         }
  78.         else {
  79.             color = 'danger'
  80.         }
  81.         started = "Build started"
  82.         slackSend channel: channel, failOnError: true, color: color, message: "${env.JOB_NAME} - ${env.BUILD_DISPLAY_NAME}\n ${started} (<${env.BUILD_URL}|Open>)"
  83.     }
  84.     else if(currentBuild.result == 'SUCCESS'){
  85.         color = 'good'
  86.         slackSend channel: channel, failOnError: true, color: color, message: "${env.JOB_NAME} - ${env.BUILD_DISPLAY_NAME} \n *${currentBuild.result}* (<${env.BUILD_URL}|Open>)"
  87.     }
  88.     else {
  89.         color = 'danger'
  90.         slackSend channel: channel, failOnError: true, color: color, message: "${env.JOB_NAME} - ${env.BUILD_DISPLAY_NAME} \n *${currentBuild.result}* (<${env.BUILD_URL}|Open>)"
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement