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 { |
| 30 | timeout(30) |
| 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 { |
| 66 | test_path = sh(script:"if [ -f \"$projectName/Gopkg.toml\" ]; then echo $WORKSPACE/go/src/github.com/opencord/$projectName; else echo $projectName; fi", returnStdout: true).trim() |
| 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 |
| 78 | echo "Found '$projectName/Gopkg.toml', assuming a golang project" |
| 79 | mkdir -p "\$GOPATH/src/github.com/opencord/" |
| 80 | mv "$WORKSPACE/$projectName" "$test_path" |
| 81 | pushd "$test_path" |
| 82 | dep ensure |
| 83 | popd |
| 84 | fi |
| 85 | """ |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
Zack Williams | 861c470 | 2019-07-02 13:41:21 -0700 | [diff] [blame] | 89 | stage ("Synopsys Detect") { |
| 90 | steps { |
| 91 | sh "echo Running Synopsys Detect on: ${projectName}" |
| 92 | |
| 93 | // Plugin: https://github.com/jenkinsci/synopsys-detect-plugin |
| 94 | // Documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect |
| 95 | // also: https://community.synopsys.com/s/article/Integrations-Documentation-Synopsys-Detect-Properties-for-version-5-4-0 |
| 96 | // also: Help menu after logging into BlackDuck portal |
| 97 | synopsys_detect("--detect.source.path=$test_path " + \ |
| 98 | "--detect.project.name=${blackduck_project}_${projectName} " + \ |
| 99 | "--detect.project.version.name=$git_tag_or_branch " + \ |
| 100 | "--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING " + \ |
| 101 | "--detect.blackduck.signature.scanner.upload.source.mode=true " + \ |
| 102 | "--detect.blackduck.signature.scanner.exclusion.patterns=/vendor/ " + \ |
| 103 | "--detect.tools=ALL " + \ |
| 104 | "--detect.cleanup=false") |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | stage ("Save Logs") { |
Zack Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 109 | steps { |
| 110 | sh returnStdout: true, script: """ |
| 111 | echo COPYING LOGS |
| 112 | mkdir -p bd_logs |
| 113 | cp -r /home/jenkins/blackduck/runs/* bd_logs |
| 114 | ls -l bd_logs/*/* |
| 115 | """ |
| 116 | archiveArtifacts artifacts:'bd_logs/**/*.*' |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |