Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | pipeline { |
| 16 | |
| 17 | /* no label, executor is determined by JJB */ |
| 18 | agent { |
| 19 | label "${params.executorNode}" |
| 20 | } |
| 21 | |
| 22 | options { |
Zack Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 23 | timeout(240) |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 24 | } |
| 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 Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 37 | writeFile file: 'get_repo_list.py', text: """ |
| 38 | #!/usr/bin/env python |
| 39 | |
| 40 | import json |
| 41 | import os |
| 42 | import requests |
| 43 | |
| 44 | if "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 | |
| 52 | else: |
| 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 |
| 67 | print(",".join(sorted(repo_list))) |
| 68 | """ |
| 69 | |
Zack Williams | b92f5d8 | 2019-05-06 22:16:40 -0700 | [diff] [blame] | 70 | /* 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 Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 74 | returnStdout: true, |
| 75 | script: "python -u get_repo_list.py").trim().split(",") |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 76 | |
Zack Williams | b92f5d8 | 2019-05-06 22:16:40 -0700 | [diff] [blame] | 77 | echo "repo list: ${repos}" |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | stage ("Checkout repos") { |
| 83 | steps { |
| 84 | script { |
| 85 | repos.each { gitRepo -> |
| 86 | sh "echo Checking out: ${gitRepo}" |
Zack Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 87 | checkout(changelog: false, scm: [ |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 88 | $class: 'GitSCM', |
| 89 | userRemoteConfigs: [[ |
Zack Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 90 | url: "${params.git_server_url}/${gitRepo}/", |
| 91 | name: "${branch}", |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 92 | ]], |
| 93 | extensions: [ |
Zack Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 94 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${gitRepo}"], |
| 95 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 96 | ], |
Zack Williams | 7903093 | 2019-05-08 15:50:36 -0700 | [diff] [blame] | 97 | ]) |
Zack Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 98 | } |
| 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 Williams | 3bf60d5 | 2019-06-07 12:56:10 -0700 | [diff] [blame] | 108 | 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 Williams | c1d6a5e | 2019-05-06 16:35:58 -0700 | [diff] [blame] | 109 | } |
| 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 | } |