blob: 8b63d892d3f82eb44aee7ac6f748ae4307cbdb1f [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 {
Zack Williamsb3292082019-10-11 17:15:18 -070020 label "${params.buildNode}"
Zack Williams3bf60d52019-06-07 12:56:10 -070021 }
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 {
Zack Williamsf5d9ef52019-09-18 06:42:55 -070030 timeout(60)
Zack Williams3bf60d52019-06-07 12:56:10 -070031 }
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 {
Zack Williamsd9a34c42019-09-26 07:56:43 -070099 // catch any errors that occur so that logs can be saved in the next stage
100 // docs: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure
101 catchError {
102 sh "echo Running Synopsys Detect on: ${projectName}"
Zack Williams861c4702019-07-02 13:41:21 -0700103
Zack Williamsd9a34c42019-09-26 07:56:43 -0700104 // Plugin: https://github.com/jenkinsci/synopsys-detect-plugin
105 // Documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/62423113/Synopsys+Detect
106 // also: https://community.synopsys.com/s/article/Integrations-Documentation-Synopsys-Detect-Properties-for-version-5-4-0
107 // also: Help menu after logging into BlackDuck portal
108 synopsys_detect("--detect.source.path=$test_path " + \
109 "--detect.project.name=${blackduck_project}_${projectName} " + \
110 "--detect.project.version.name=$git_tag_or_branch " + \
111 "--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING " + \
112 "--detect.blackduck.signature.scanner.upload.source.mode=true " + \
113 "--detect.blackduck.signature.scanner.exclusion.patterns=/vendor/ " + \
114 "--detect.policy.check.fail.on.severities=ALL,BLOCKER,CRITICAL,MAJOR,MINOR,TRIVIAL " + \
115 "--detect.report.timeout=3600 " + \
116 "--detect.tools=ALL " + \
117 "--detect.cleanup=false")
118 }
Zack Williams861c4702019-07-02 13:41:21 -0700119 }
120 }
121
122 stage ("Save Logs") {
Zack Williams3bf60d52019-06-07 12:56:10 -0700123 steps {
124 sh returnStdout: true, script: """
125 echo COPYING LOGS
126 mkdir -p bd_logs
127 cp -r /home/jenkins/blackduck/runs/* bd_logs
128 ls -l bd_logs/*/*
129 """
130 archiveArtifacts artifacts:'bd_logs/**/*.*'
131 }
132 }
133 }
134}