blob: 96a3bd0a982f56abc2067f7787a4f4f09436bdd8 [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 {
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 Williams3bf60d52019-06-07 12:56:10 -070086 }
87 }
88
Zack Williams861c4702019-07-02 13:41:21 -070089 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 Williams3bf60d52019-06-07 12:56:10 -0700109 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}