blob: 2cbef34b2b7958a89887a7aad5c9ee9dd26c9008 [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',
45 userRemoteConfigs: [[
46 url: "${params.gitUrl}",
47 name: "${params.gitRef}",
48 ]],
49 extensions: [
50 [$class: 'WipeWorkspace'],
51 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.projectName}"],
52 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
53 ],
54 ])
Zack Williams861c4702019-07-02 13:41:21 -070055
56 // Used later to set the branch/tag in the blackduck UI release
Zack Williams3bf60d52019-06-07 12:56:10 -070057 script {
Zack Williams4f8c8002019-06-25 08:39:49 -070058 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 -070059 }
60 }
61 }
62
Zack Williams861c4702019-07-02 13:41:21 -070063 stage ("Prepare") {
Zack Williams3bf60d52019-06-07 12:56:10 -070064 steps {
Zack Williams861c4702019-07-02 13:41:21 -070065
66 // change the path tested if for golang projects which expect to be found in GOPATH
67 script {
68 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()
69 }
70
71 sh returnStdout: true, script: """
72 if [ -f "$projectName/package.json" ]
73 then
74 echo "Found '$projectName/package.json', assuming a Node.js project, running npm install"
75 pushd "$projectName"
76 npm install
77 popd
78 elif [ -f "$projectName/Gopkg.toml" ]
79 then
80 echo "Found '$projectName/Gopkg.toml', assuming a golang project"
81 mkdir -p "\$GOPATH/src/github.com/opencord/"
82 mv "$WORKSPACE/$projectName" "$test_path"
83 pushd "$test_path"
84 dep ensure
85 popd
86 fi
87 """
Zack Williams3bf60d52019-06-07 12:56:10 -070088 }
89 }
90
Zack Williams861c4702019-07-02 13:41:21 -070091 stage ("Synopsys Detect") {
92 steps {
93 sh "echo Running Synopsys Detect on: ${projectName}"
94
95 // Plugin: https://github.com/jenkinsci/synopsys-detect-plugin
96 // Documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect
97 // also: https://community.synopsys.com/s/article/Integrations-Documentation-Synopsys-Detect-Properties-for-version-5-4-0
98 // also: Help menu after logging into BlackDuck portal
99 synopsys_detect("--detect.source.path=$test_path " + \
100 "--detect.project.name=${blackduck_project}_${projectName} " + \
101 "--detect.project.version.name=$git_tag_or_branch " + \
102 "--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING " + \
103 "--detect.blackduck.signature.scanner.upload.source.mode=true " + \
104 "--detect.blackduck.signature.scanner.exclusion.patterns=/vendor/ " + \
105 "--detect.tools=ALL " + \
106 "--detect.cleanup=false")
107 }
108 }
109
110 stage ("Save Logs") {
Zack Williams3bf60d52019-06-07 12:56:10 -0700111 steps {
112 sh returnStdout: true, script: """
113 echo COPYING LOGS
114 mkdir -p bd_logs
115 cp -r /home/jenkins/blackduck/runs/* bd_logs
116 ls -l bd_logs/*/*
117 """
118 archiveArtifacts artifacts:'bd_logs/**/*.*'
119 }
120 }
121 }
122}