Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. #!/usr/bin/env groovy
  2.  
  3. import hudson.model.*
  4. import hudson.Util;
  5. import org.codehaus.groovy.runtime.StackTraceUtils
  6.  
  7. contentDir = "${JENKINS_HOME}/userContent"
  8. USAT_ENVIRONMENT = "DEV"
  9. USAT_GIT_BRANCH = "master"
  10. USAT_GIT_CHECKOUT = "Y"
  11. USAT_VERSION = "${USAT_GIT_BRANCH}-$BUILD_TIMESTAMP"
  12. gitRepo = 'file:///opt/USAT/git/NetworkServices.git'
  13. def runExtension = ''
  14. def prepareSteps = [:]
  15. def buildSteps = [:]
  16. def veracodeUploadSteps = [:]
  17. def veracodeRescanSteps = [:]
  18. def stackTrace = null
  19. try {
  20. node {
  21. timestamps {
  22. wrap([$class: 'BuildUser']) {
  23. stage ('Prepare')
  24. {
  25. echo 'Preparing...'
  26. def stepCounter = 0
  27.  
  28. if (prepareSteps.size() > 0) {
  29. parallel(prepareSteps)
  30. }
  31. echo 'Finished Preparing'
  32. }
  33.  
  34. stage ('Veracode Upload') {
  35. veracodeUploadStep(veracodeUploadSteps, 'Y', 'Loader', 'Loader')
  36. veracodeUploadStep(veracodeUploadSteps, 'Y', 'InAuthLayer', 'AuthorityLayer')
  37. veracodeUploadStep(veracodeUploadSteps, 'Y', 'DMS', 'DMS')
  38. }
  39.  
  40. stage ('Veracode Rescan') {
  41. executeParallelSteps(veracodeRescanSteps)
  42. }
  43.  
  44.  
  45. }
  46. }
  47. }
  48. } catch (exc) {
  49. if (env.USAT_ENVIRONMENT == null) {
  50. echo exc.toString()
  51. } else {
  52. currentBuild.result = 'FAILURE'
  53. throw exc
  54. }
  55. } finally {
  56. if (currentBuild.result == null || currentBuild.result.trim() == '') {
  57. currentBuild.result = 'SUCCESS'
  58. }
  59.  
  60.  
  61. }
  62.  
  63.  
  64. def run(cmd) {
  65. if (Boolean.valueOf(env.UNIX)) {
  66. sh cmd
  67. } else {
  68. bat cmd
  69. }
  70. }
  71.  
  72.  
  73. def buildStep(buildSteps, buildAllInd, buildAppInd, appLabel, appProject, buildTarget, unzipInd, appPath, libPath, filesToLink) {
  74.  
  75. def buildOptions = "-Dmode=Fast -Dgit-repo=${gitRepo} -Dgit-branch=${USAT_GIT_BRANCH} -Dversion=${USAT_VERSION} -Denvironment=${USAT_ENVIRONMENT}"
  76. if (appProject == 'ServerLayers/TestClient') {
  77. //TestClient has builds for multiple apps
  78. buildOptions += ' -Dapp=' + appLabel.replaceAll('[^a-zA-Z0-9]', '')
  79. }
  80.  
  81. if (libPath != null) {
  82. buildOptions += " -Dlib-path=${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${libPath}"
  83. }
  84. buildSteps[appLabel] = {
  85. echo "Building $appLabel..."
  86. run "ant -buildfile ${WORKSPACE}/${USAT_ENVIRONMENT}/$appProject/build.xml ${buildOptions} ${buildTarget}"
  87. echo "Built $appLabel"
  88. if (unzipInd == 'Y') {
  89. echo "Unzipping $appLabel..."
  90. run "unzip -o ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${appPath}.zip -d ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/$appPath"
  91. echo "Unzipped $appLabel"
  92. }
  93. if (filesToLink != null) {
  94. for (def fileToLink : filesToLink.split(', ')) {
  95. run "ln -f -s ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${fileToLink}-${USAT_VERSION}.tar.gz ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${fileToLink}-${USAT_GIT_BRANCH}-latest.tar.gz"
  96. }
  97. }
  98. }
  99.  
  100. }
  101.  
  102. def veracodeUploadStep(veracodeUploadSteps, uploadApp, appLabel, appName) {
  103. if(uploadApp == 'Y'){
  104.  
  105. veracode applicationName: 'Veracode_nightly', uploadExcludesPattern: '', uploadIncludesPattern: '**/**.tar.gz', createSandbox: true, criticality: 'VeryHigh', debug: true, fileNamePattern: '', replacementPattern: '', sandboxName: '$projectname', scanExcludesPattern: '', scanIncludesPattern: '', scanName: '$timestamp', teams: '', useIDkey: true, version:'$USAT_VERSION', vid: '3a8b05b51c1ab7e64f226d963300919b', vkey: '8ee60f259d551a663c84e153f4cc98efa412e98636b3570c61b8254e40146023f4b897b3464ed541ac220320d8ab7a49b7797f5f4824f82b8a74c8aaee36023e', vpassword: '', vuser: ''
  106.  
  107. }}
  108. def veracodeRescanStep(veracodeRescanSteps, scanApp, appLabel, appName) {
  109. if(scanApp == 'Y'){
  110. veracodeRescanSteps[appLabel] = {
  111. veracodeDynamicRescan applicationName: 'Veracode_nightly', dvrEnabled: true, pHost: '', pPassword: '',pUser: '', useIDkey: true, vid: '3a8b05b51c1ab7e64f226d963300919b',vkey: '8ee60f259d551a663c84e153f4cc98efa412e98636b3570c61b8254e40146023f4b897b3464ed541ac220320d8ab7a49b7797f5f4824f82b8a74c8aaee36023e',vpassword: '', vuser: ''
  112. }}}
  113.  
  114.  
  115. def filesExist(filePath) {
  116. def foundFiles = findFiles(glob: filePath)
  117. return foundFiles.length > 0
  118. }
  119.  
  120.  
  121.  
  122. def executeParallelSteps(parallelSteps) {
  123. def stepCount = parallelSteps.size()
  124. if (stepCount == 0) {
  125. parallelSteps['Skipped'] = {}
  126. }
  127. parallel(parallelSteps)
  128. return stepCount
  129. }
  130.  
  131.  
  132.  
  133. def getProperties(propertiesFile) {
  134. if (!fileExists(propertiesFile)) {
  135. error "File ${propertiesFile} does not exist"
  136. }
  137. def properties = readProperties file: propertiesFile
  138. return properties
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement