Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. print "----------------------------------------------------"
  2. print " JMeter Testing"
  3. print "----------------------------------------------------"
  4.  
  5. node('jenkins-agent'){
  6.  
  7. workspace = pwd() // Set the main workspace in your Jenkins agent
  8.  
  9. authToken = "" // Get your user auth token for OpenShift
  10. apiURL = "" // URL for your OpenShift cluster API
  11.  
  12. gitUser = "" // Set your Git username
  13. gitPass = "" // Set your Git password
  14. gitURL = "" // Set the URL of your test suite repo
  15. gitName = "" // Set the name of your test suite repo
  16. gitBranch = "" // Set the branch of your test suite repo
  17.  
  18. jenkinsUser = "" // Set username for Jenkins
  19. jenkinsPass = "" // Set API token for Jenkins
  20.  
  21. // Set location of OpenShift objects in workspace
  22. buildConfigPath = "${workspace}/${gitName}/ocp/build-config.yaml"
  23. imageStreamPath = "${workspace}/${gitName}/ocp/image-stream.yaml"
  24. jobTemplatePath = "${workspace}/${gitName}/ocp/job-template.yaml"
  25.  
  26. project = "" // Set the OpenShift project you're working in
  27. testSuiteName = "jmeter-test-suite" // Name of the job/build/imagestream
  28.  
  29. // Login to the OpenShift cluster
  30. sh """
  31. set +x
  32. oc login --insecure-skip-tls-verify=true --token=${authToken} ${apiURL}
  33. """
  34.  
  35. // Checkout the test suite repo into your Jenkins agent workspace
  36. int slashIdx = gitURL.indexOf("://")
  37. String urlWithCreds = gitURL.substring(0, slashIdx + 3) +
  38. "\"${gitUser}:${gitPass}\"@" + gitURL.substring(slashIdx + 3);
  39.  
  40. sh """
  41. rm -rf ${workspace}/${gitName}
  42. git clone -b ${gitBranch} ${urlWithCreds} ${gitName}
  43. echo `pwd && ls -l`
  44. """
  45.  
  46. // Create your ImageStream and BuildConfig in OpenShift
  47. // Then start the build for the test suite image
  48. sh """
  49. oc apply -f ${imageStreamPath} -n ${project}
  50. oc apply -f ${buildConfigPath} -n ${project}
  51. oc start-build ${testSuiteName} -n ${project} --follow
  52. """
  53.  
  54. // Get latest JMeter image from project to assign to job template
  55. String imageURL = sh (
  56. script:"""
  57. oc get is/rhel-${testSuiteName} -n ${project} --output=jsonpath={.status.dockerImageRepository}
  58. """,
  59. returnStdout: true
  60. )
  61.  
  62. // Get all JMX files from JMeter directory
  63. // Pipeline Utility Steps Plugin --> findFiles
  64. String files = findFiles(glob: 'jmeter/*.jmx')
  65.  
  66. // Split file names into testFileNames array
  67. testFileNames = files.split('\n')
  68.  
  69. // For every test file, run job and get results back
  70. for (int i=0; i<testFileNames.size(); i++) {
  71.  
  72. // Get file name without .jmx
  73. file = testFileNames[i]
  74. fileName = file.replaceAll('.jmx','')
  75.  
  76. print "Running JMeter tests: ${fileName}"
  77.  
  78. // Set the return URL for the Jenkins input step
  79. inputURL = env.BUILD_URL + "input/Jmeter-${fileName}/submit"
  80.  
  81. // Delete existing test suite job for previous JMX file
  82. // Create new test suite job with current file
  83. // Pass in input URL, Jenkins username/password, and image
  84. sh """
  85. oc delete job/${testSuiteName} -n ${project} --ignore-not-found=true
  86.  
  87. oc process -f ${jobTemplatePath} -p \
  88. JENKINS_PIPELINE_RETURN_URL=${inputURL} \
  89. FILE_NAME=${fileName} \
  90. USER_NAME=${jenkinsUser} \
  91. PASSWORD=${jenkinsPass} \
  92. IMAGE=${imageURL}:latest \
  93. -n ${project} | oc create -f - -n ${project}
  94. """
  95.  
  96. // Block and wait for job to return with results file
  97. // The input ID is what creates the unique return URL for curling back
  98. print "Waiting for results from JMeter test job..."
  99. def inputFile = input id: "Jmeter-${fileName}",
  100. message: 'Waiting for JMeter results...',
  101. parameters: [
  102. file(description: 'Performance Test Results',
  103. name: "${fileName}") // This must match the name param in runjob.sh
  104. ]
  105.  
  106. // Running Performance Plugin with JMeter to show results
  107. // The results JTL file is saved on the master Jenkins node,
  108. // inputFile.toString() gives you the absolute path of the file to parse
  109. //
  110. // These threshold values can be whatever you like
  111. performanceReport compareBuildPrevious: false,
  112. configType: 'ART',
  113. errorFailedThreshold: 0,
  114. errorUnstableResponseTimeThreshold: '',
  115. errorUnstableThreshold: 0,
  116. failBuildIfNoResultFile: false,
  117. ignoreFailedBuild: false,
  118. ignoreUnstableBuild: true,
  119. modeOfThreshold: false,
  120. modePerformancePerTestCase: true,
  121. modeThroughput: true,
  122. nthBuildNumber: 0,
  123. parsers: [[$class: 'JMeterParser', glob: inputFile.toString()]],
  124. relativeFailedThresholdNegative: 0,
  125. relativeFailedThresholdPositive: 0,
  126. relativeUnstableThresholdNegative: 0,
  127. relativeUnstableThresholdPositive: 0
  128. } // for loop
  129. } // node
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement