Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 1 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | // you may not use this file except in compliance with the License. |
| 3 | // You may obtain a copy of the License at |
| 4 | // |
| 5 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | // |
| 7 | // Unless required by applicable law or agreed to in writing, software |
| 8 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | // See the License for the specific language governing permissions and |
| 11 | // limitations under the License. |
| 12 | |
| 13 | // synopsys-single.groovy |
| 14 | // checks a single repo against synopsys |
| 15 | |
| 16 | pipeline { |
| 17 | |
| 18 | /* no label, executor is determined by JJB */ |
| 19 | agent { |
| 20 | label "${params.executorNode}" |
| 21 | } |
| 22 | |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 23 | // Set so that synopsys_detect will know where to run golang tools from |
| 24 | environment { |
| 25 | PATH = "$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin/:$WORKSPACE/go/bin" |
| 26 | GOPATH = "$WORKSPACE/go" |
| 27 | } |
| 28 | |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 29 | options { |
Zack Williams | f5d9ef5 | 2019-09-18 06:42:55 -0700 | [diff] [blame] | 30 | timeout(60) |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | stages { |
| 34 | |
| 35 | stage ("Clean workspace") { |
| 36 | steps { |
| 37 | sh 'rm -rf *' |
| 38 | } |
| 39 | } |
| 40 | |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 41 | stage('Checkout') { |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 42 | steps { |
| 43 | checkout([ |
| 44 | $class: 'GitSCM', |
Zack Williams | 9933027 | 2019-08-21 11:33:48 -0700 | [diff] [blame] | 45 | userRemoteConfigs: [[ url: "${params.gitUrl}", ]], |
| 46 | branches: [[ name: "${params.gitRef}", ]], |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 47 | extensions: [ |
| 48 | [$class: 'WipeWorkspace'], |
| 49 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"], |
| 50 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 51 | ], |
| 52 | ]) |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 53 | |
| 54 | // Used later to set the branch/tag in the blackduck UI release |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 55 | script { |
Zack Williams | 4f8c800 | 2019-06-25 08:39:49 -0700 | [diff] [blame] | 56 | git_tag_or_branch = sh(script:"cd $projectName; if [[ \$(git tag -l --points-at HEAD) ]]; then git tag -l --points-at HEAD; else echo ${branchName}; fi", returnStdout: true).trim() |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 61 | stage ("Prepare") { |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 62 | steps { |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 63 | |
| 64 | // change the path tested if for golang projects which expect to be found in GOPATH |
| 65 | script { |
Zack Williams | dd300de | 2019-08-19 20:43:29 -0700 | [diff] [blame] | 66 | test_path = sh(script:"if [ -f \"$projectName/Gopkg.toml\" ] || [ -f \"$projectName/go.mod\" ] ; then echo $WORKSPACE/go/src/github.com/opencord/$projectName; else echo $projectName; fi", returnStdout: true).trim() |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | sh returnStdout: true, script: """ |
| 70 | if [ -f "$projectName/package.json" ] |
| 71 | then |
| 72 | echo "Found '$projectName/package.json', assuming a Node.js project, running npm install" |
| 73 | pushd "$projectName" |
| 74 | npm install |
| 75 | popd |
| 76 | elif [ -f "$projectName/Gopkg.toml" ] |
| 77 | then |
Zack Williams | dd300de | 2019-08-19 20:43:29 -0700 | [diff] [blame] | 78 | echo "Found '$projectName/Gopkg.toml', assuming a golang project using dep" |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 79 | mkdir -p "\$GOPATH/src/github.com/opencord/" |
| 80 | mv "$WORKSPACE/$projectName" "$test_path" |
| 81 | pushd "$test_path" |
| 82 | dep ensure |
| 83 | popd |
Zack Williams | dd300de | 2019-08-19 20:43:29 -0700 | [diff] [blame] | 84 | elif [ -f "$projectName/go.mod" ] |
| 85 | then |
| 86 | echo "Found '$projectName/go.mod', assuming a golang project using go modules" |
| 87 | mkdir -p "\$GOPATH/src/github.com/opencord/" |
| 88 | mv "$WORKSPACE/$projectName" "$test_path" |
| 89 | pushd "$test_path" |
| 90 | make dep |
| 91 | popd |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 92 | fi |
| 93 | """ |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 97 | stage ("Synopsys Detect") { |
| 98 | steps { |
| 99 | sh "echo Running Synopsys Detect on: ${projectName}" |
| 100 | |
| 101 | // Plugin: https://github.com/jenkinsci/synopsys-detect-plugin |
| 102 | // Documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect |
| 103 | // also: https://community.synopsys.com/s/article/Integrations-Documentation-Synopsys-Detect-Properties-for-version-5-4-0 |
| 104 | // also: Help menu after logging into BlackDuck portal |
| 105 | synopsys_detect("--detect.source.path=$test_path " + \ |
| 106 | "--detect.project.name=${blackduck_project}_${projectName} " + \ |
| 107 | "--detect.project.version.name=$git_tag_or_branch " + \ |
| 108 | "--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING " + \ |
| 109 | "--detect.blackduck.signature.scanner.upload.source.mode=true " + \ |
| 110 | "--detect.blackduck.signature.scanner.exclusion.patterns=/vendor/ " + \ |
Zack Williams | c053f61 | 2019-08-29 10:19:00 -0700 | [diff] [blame] | 111 | "--detect.policy.check.fail.on.severities=ALL,BLOCKER,CRITICAL,MAJOR,MINOR,TRIVIAL " + \ |
Zack Williams | f5d9ef5 | 2019-09-18 06:42:55 -0700 | [diff] [blame] | 112 | "--detect.report.timeout=3600 " + \ |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 113 | "--detect.tools=ALL " + \ |
| 114 | "--detect.cleanup=false") |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | stage ("Save Logs") { |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 119 | steps { |
| 120 | sh returnStdout: true, script: """ |
| 121 | echo COPYING LOGS |
| 122 | mkdir -p bd_logs |
| 123 | cp -r /home/jenkins/blackduck/runs/* bd_logs |
| 124 | ls -l bd_logs/*/* |
| 125 | """ |
| 126 | archiveArtifacts artifacts:'bd_logs/**/*.*' |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |