blob: db890f89e34ed50e9a74dc349fcdaae593909217 [file] [log] [blame]
Zack Williams3bf60d52019-06-07 12:56:10 -07001// 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
16pipeline {
17
18 /* no label, executor is determined by JJB */
19 agent {
20 label "${params.executorNode}"
21 }
22
Zack Williams861c4702019-07-02 13:41:21 -070023 // 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 Williams3bf60d52019-06-07 12:56:10 -070029 options {
30 timeout(30)
31 }
32
33 stages {
34
35 stage ("Clean workspace") {
36 steps {
37 sh 'rm -rf *'
38 }
39 }
40
Zack Williams861c4702019-07-02 13:41:21 -070041 stage('Checkout') {
Zack Williams3bf60d52019-06-07 12:56:10 -070042 steps {
43 checkout([
44 $class: 'GitSCM',
Zack Williams99330272019-08-21 11:33:48 -070045 userRemoteConfigs: [[ url: "${params.gitUrl}", ]],
46 branches: [[ name: "${params.gitRef}", ]],
Zack Williams3bf60d52019-06-07 12:56:10 -070047 extensions: [
48 [$class: 'WipeWorkspace'],
49 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
50 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
51 ],
52 ])
Zack Williams861c4702019-07-02 13:41:21 -070053
54 // Used later to set the branch/tag in the blackduck UI release
Zack Williams3bf60d52019-06-07 12:56:10 -070055 script {
Zack Williams4f8c8002019-06-25 08:39:49 -070056 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 Williams3bf60d52019-06-07 12:56:10 -070057 }
58 }
59 }
60
Zack Williams861c4702019-07-02 13:41:21 -070061 stage ("Prepare") {
Zack Williams3bf60d52019-06-07 12:56:10 -070062 steps {
Zack Williams861c4702019-07-02 13:41:21 -070063
64 // change the path tested if for golang projects which expect to be found in GOPATH
65 script {
Zack Williamsdd300de2019-08-19 20:43:29 -070066 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 Williams861c4702019-07-02 13:41:21 -070067 }
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 Williamsdd300de2019-08-19 20:43:29 -070078 echo "Found '$projectName/Gopkg.toml', assuming a golang project using dep"
Zack Williams861c4702019-07-02 13:41:21 -070079 mkdir -p "\$GOPATH/src/github.com/opencord/"
80 mv "$WORKSPACE/$projectName" "$test_path"
81 pushd "$test_path"
82 dep ensure
83 popd
Zack Williamsdd300de2019-08-19 20:43:29 -070084 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 Williams861c4702019-07-02 13:41:21 -070092 fi
93 """
Zack Williams3bf60d52019-06-07 12:56:10 -070094 }
95 }
96
Zack Williams861c4702019-07-02 13:41:21 -070097 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 Williamsc053f612019-08-29 10:19:00 -0700111 "--detect.policy.check.fail.on.severities=ALL,BLOCKER,CRITICAL,MAJOR,MINOR,TRIVIAL " + \
Zack Williams4a015042019-08-30 10:58:22 -0700112 "--detect.report.timeout=900 " + \
Zack Williams861c4702019-07-02 13:41:21 -0700113 "--detect.tools=ALL " + \
114 "--detect.cleanup=false")
115 }
116 }
117
118 stage ("Save Logs") {
Zack Williams3bf60d52019-06-07 12:56:10 -0700119 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}