blob: c0fca9497d49aa5df6ee5dbbfdc167232908a18c [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
22 options {
Zack Williams79030932019-05-08 15:50:36 -070023 timeout(240)
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070024 }
25
26 stages {
27
28 stage ("Clean workspace") {
29 steps {
30 sh 'rm -rf *'
31 }
32 }
33
34 stage ("Get repo list") {
35 steps {
36 script {
Zack Williams79030932019-05-08 15:50:36 -070037 writeFile file: 'get_repo_list.py', text: """
38#!/usr/bin/env python
39
40import json
41import os
42import requests
43
44if "github_organization" in os.environ:
45 # this is a github org
46 github_req = requests.get("https://api.github.com/orgs/%s/repos" %
47 os.environ["github_organization"])
48
49 # pull out the "name" key out of each item
50 repo_list = map(lambda item: item["name"], github_req.json())
51
52else:
53 # this is a gerrit server
54
55 # fetch the list of projects
56 gerrit_req = requests.get("%s/projects/?pp=0" %
57 os.environ["git_server_url"])
58 # remove XSSI prefix
59 # https://gerrit-review.googlesource.com/Documentation/rest-api.html#output
60 gerrit_json = json.loads(gerrit_req.text.splitlines()[1])
61
62 # remove repos which don't contain code
63 repo_list = [repo for repo in gerrit_json.keys()
64 if repo not in ["All-Projects", "All-Users", "voltha-bal"]]
65
66# sort and print
67print(",".join(sorted(repo_list)))
68"""
69
Zack Williamsb92f5d82019-05-06 22:16:40 -070070 /* this defines the variable globally - not ideal, but works - see:
71 https://stackoverflow.com/questions/50571316/strange-variable-scoping-behavior-in-jenkinsfile
72 */
73 repos = sh(
Zack Williams79030932019-05-08 15:50:36 -070074 returnStdout: true,
75 script: "python -u get_repo_list.py").trim().split(",")
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070076
Zack Williamsb92f5d82019-05-06 22:16:40 -070077 echo "repo list: ${repos}"
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070078 }
79 }
80 }
81
82 stage ("Checkout repos") {
83 steps {
84 script {
85 repos.each { gitRepo ->
86 sh "echo Checking out: ${gitRepo}"
Zack Williams79030932019-05-08 15:50:36 -070087 checkout(changelog: false, scm: [
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070088 $class: 'GitSCM',
89 userRemoteConfigs: [[
Zack Williams79030932019-05-08 15:50:36 -070090 url: "${params.git_server_url}/${gitRepo}/",
91 name: "${branch}",
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070092 ]],
93 extensions: [
Zack Williams79030932019-05-08 15:50:36 -070094 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${gitRepo}"],
95 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070096 ],
Zack Williams79030932019-05-08 15:50:36 -070097 ])
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070098 }
99 }
100 }
101 }
102
103 stage ("Synopsys Detect") {
104 steps {
105 script {
106 repos.each { gitRepo ->
107 sh "echo Running Synopsys Detect on: ${gitRepo}"
Zack Williams3bf60d52019-06-07 12:56:10 -0700108 synopsys_detect("--detect.source.path=${gitRepo} --detect.project.name=${blackduck_project}_${gitRepo} --detect.project.version.name=${branch} --detect.blackduck.signature.scanner.snippet.mode=true --detect.tools=ALL --detect.cleanup=false")
Zack Williamsc1d6a5e2019-05-06 16:35:58 -0700109 }
110 }
111 }
112 }
113
114 stage ("Save logs") {
115 steps {
116 sh returnStdout: true, script: """
117 echo COPYING LOGS
118 mkdir -p bd_logs
119 cp -r /home/jenkins/blackduck/runs/* bd_logs
120 ls -l bd_logs/*/*
121 """
122 archiveArtifacts artifacts:'bd_logs/**/*.*'
123 }
124 }
125 }
126}