Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env groovy
- import hudson.model.*
- import hudson.Util;
- import org.codehaus.groovy.runtime.StackTraceUtils
- contentDir = "${JENKINS_HOME}/userContent"
- USAT_ENVIRONMENT = "DEV"
- USAT_GIT_BRANCH = "master"
- USAT_GIT_CHECKOUT = "Y"
- USAT_VERSION = "${USAT_GIT_BRANCH}-$BUILD_TIMESTAMP"
- gitRepo = 'file:///opt/USAT/git/NetworkServices.git'
- def runExtension = ''
- def prepareSteps = [:]
- def buildSteps = [:]
- def veracodeUploadSteps = [:]
- def veracodeRescanSteps = [:]
- def stackTrace = null
- try {
- node {
- timestamps {
- wrap([$class: 'BuildUser']) {
- stage ('Prepare')
- {
- echo 'Preparing...'
- def stepCounter = 0
- if (prepareSteps.size() > 0) {
- parallel(prepareSteps)
- }
- echo 'Finished Preparing'
- }
- stage ('Veracode Upload') {
- veracodeUploadStep(veracodeUploadSteps, 'Y', 'Loader', 'Loader')
- veracodeUploadStep(veracodeUploadSteps, 'Y', 'InAuthLayer', 'AuthorityLayer')
- veracodeUploadStep(veracodeUploadSteps, 'Y', 'DMS', 'DMS')
- }
- stage ('Veracode Rescan') {
- executeParallelSteps(veracodeRescanSteps)
- }
- }
- }
- }
- } catch (exc) {
- if (env.USAT_ENVIRONMENT == null) {
- echo exc.toString()
- } else {
- currentBuild.result = 'FAILURE'
- throw exc
- }
- } finally {
- if (currentBuild.result == null || currentBuild.result.trim() == '') {
- currentBuild.result = 'SUCCESS'
- }
- }
- def run(cmd) {
- if (Boolean.valueOf(env.UNIX)) {
- sh cmd
- } else {
- bat cmd
- }
- }
- def buildStep(buildSteps, buildAllInd, buildAppInd, appLabel, appProject, buildTarget, unzipInd, appPath, libPath, filesToLink) {
- def buildOptions = "-Dmode=Fast -Dgit-repo=${gitRepo} -Dgit-branch=${USAT_GIT_BRANCH} -Dversion=${USAT_VERSION} -Denvironment=${USAT_ENVIRONMENT}"
- if (appProject == 'ServerLayers/TestClient') {
- //TestClient has builds for multiple apps
- buildOptions += ' -Dapp=' + appLabel.replaceAll('[^a-zA-Z0-9]', '')
- }
- if (libPath != null) {
- buildOptions += " -Dlib-path=${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${libPath}"
- }
- buildSteps[appLabel] = {
- echo "Building $appLabel..."
- run "ant -buildfile ${WORKSPACE}/${USAT_ENVIRONMENT}/$appProject/build.xml ${buildOptions} ${buildTarget}"
- echo "Built $appLabel"
- if (unzipInd == 'Y') {
- echo "Unzipping $appLabel..."
- run "unzip -o ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${appPath}.zip -d ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/$appPath"
- echo "Unzipped $appLabel"
- }
- if (filesToLink != null) {
- for (def fileToLink : filesToLink.split(', ')) {
- run "ln -f -s ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${fileToLink}-${USAT_VERSION}.tar.gz ${WORKSPACE}/NetworkBuilds/ApplicationBuilds/${fileToLink}-${USAT_GIT_BRANCH}-latest.tar.gz"
- }
- }
- }
- }
- def veracodeUploadStep(veracodeUploadSteps, uploadApp, appLabel, appName) {
- if(uploadApp == 'Y'){
- 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: ''
- }}
- def veracodeRescanStep(veracodeRescanSteps, scanApp, appLabel, appName) {
- if(scanApp == 'Y'){
- veracodeRescanSteps[appLabel] = {
- veracodeDynamicRescan applicationName: 'Veracode_nightly', dvrEnabled: true, pHost: '', pPassword: '',pUser: '', useIDkey: true, vid: '3a8b05b51c1ab7e64f226d963300919b',vkey: '8ee60f259d551a663c84e153f4cc98efa412e98636b3570c61b8254e40146023f4b897b3464ed541ac220320d8ab7a49b7797f5f4824f82b8a74c8aaee36023e',vpassword: '', vuser: ''
- }}}
- def filesExist(filePath) {
- def foundFiles = findFiles(glob: filePath)
- return foundFiles.length > 0
- }
- def executeParallelSteps(parallelSteps) {
- def stepCount = parallelSteps.size()
- if (stepCount == 0) {
- parallelSteps['Skipped'] = {}
- }
- parallel(parallelSteps)
- return stepCount
- }
- def getProperties(propertiesFile) {
- if (!fileExists(propertiesFile)) {
- error "File ${propertiesFile} does not exist"
- }
- def properties = readProperties file: propertiesFile
- return properties
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement