blob: e413117e89c2de07f89b05f8515be0ed3f93cdc3 [file] [log] [blame]
Zack Williamsc1d6a5e2019-05-06 16:35:58 -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-check.groovy
14
15pipeline {
16
17 /* no label, executor is determined by JJB */
18 agent {
19 label "${params.executorNode}"
20 }
21
Zack Williams861c4702019-07-02 13:41:21 -070022 // Set so that synopsys_detect will know where to run golang tools from
23 environment {
24 PATH = "$PATH:/usr/lib/go-1.12/bin:/usr/local/go/bin/:$WORKSPACE/go/bin"
25 GOPATH = "$WORKSPACE/go"
26 }
27
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070028 options {
Zack Williams79030932019-05-08 15:50:36 -070029 timeout(240)
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070030 }
31
32 stages {
33
34 stage ("Clean workspace") {
35 steps {
36 sh 'rm -rf *'
37 }
38 }
39
40 stage ("Get repo list") {
41 steps {
42 script {
Zack Williams79030932019-05-08 15:50:36 -070043 writeFile file: 'get_repo_list.py', text: """
44#!/usr/bin/env python
45
46import json
47import os
48import requests
49
50if "github_organization" in os.environ:
51 # this is a github org
52 github_req = requests.get("https://api.github.com/orgs/%s/repos" %
53 os.environ["github_organization"])
54
55 # pull out the "name" key out of each item
56 repo_list = map(lambda item: item["name"], github_req.json())
57
58else:
59 # this is a gerrit server
60
61 # fetch the list of projects
62 gerrit_req = requests.get("%s/projects/?pp=0" %
63 os.environ["git_server_url"])
64 # remove XSSI prefix
65 # https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
66 gerrit_json = json.loads(gerrit_req.text.splitlines()[1])
67
68 # remove repos which don't contain code
69 repo_list = [repo for repo in gerrit_json.keys()
70 if repo not in ["All-Projects", "All-Users", "voltha-bal"]]
71
72# sort and print
73print(",".join(sorted(repo_list)))
74"""
75
Zack Williamsb92f5d82019-05-06 22:16:40 -070076 /* this defines the variable globally - not ideal, but works - see:
77 https://stackoverflow.com/questions/50571316/strange-variable-scoping-behavior-in-jenkinsfile
78 */
79 repos = sh(
Zack Williams79030932019-05-08 15:50:36 -070080 returnStdout: true,
81 script: "python -u get_repo_list.py").trim().split(",")
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070082
Zack Williamsb92f5d82019-05-06 22:16:40 -070083 echo "repo list: ${repos}"
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070084 }
85 }
86 }
87
88 stage ("Checkout repos") {
89 steps {
90 script {
91 repos.each { gitRepo ->
92 sh "echo Checking out: ${gitRepo}"
Zack Williams79030932019-05-08 15:50:36 -070093 checkout(changelog: false, scm: [
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070094 $class: 'GitSCM',
Zack Williams99330272019-08-21 11:33:48 -070095 userRemoteConfigs: [[ url: "${params.git_server_url}/${gitRepo}/", ]],
96 branches: [[ name: "${branch}", ]],
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070097 extensions: [
Zack Williams79030932019-05-08 15:50:36 -070098 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${gitRepo}"],
99 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
Zack Williamsc1d6a5e2019-05-06 16:35:58 -0700100 ],
Zack Williams79030932019-05-08 15:50:36 -0700101 ])
Zack Williamsc1d6a5e2019-05-06 16:35:58 -0700102 }
103 }
104 }
105 }
106
107 stage ("Synopsys Detect") {
108 steps {
109 script {
110 repos.each { gitRepo ->
111 sh "echo Running Synopsys Detect on: ${gitRepo}"
Zack Williams861c4702019-07-02 13:41:21 -0700112 synopsys_detect("--detect.source.path=${gitRepo} " + \
113 "--detect.project.name=${blackduck_project}_${projectName} " + \
114 "--detect.project.version.name=$git_tag_or_branch " + \
115 "--detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING " + \
116 "--detect.blackduck.signature.scanner.upload.source.mode=true " + \
117 "--detect.blackduck.signature.scanner.exclusion.patterns=/vendor/ " + \
118 "--detect.tools=ALL " + \
119 "--detect.cleanup=false")
Zack Williamsc1d6a5e2019-05-06 16:35:58 -0700120 }
121 }
122 }
123 }
124
125 stage ("Save logs") {
126 steps {
127 sh returnStdout: true, script: """
128 echo COPYING LOGS
129 mkdir -p bd_logs
130 cp -r /home/jenkins/blackduck/runs/* bd_logs
131 ls -l bd_logs/*/*
132 """
133 archiveArtifacts artifacts:'bd_logs/**/*.*'
134 }
135 }
136 }
137}