blob: b46e470aa302a6162680cfd25462df59676e7d3d [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 {
23 timeout(30)
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 Williamsb92f5d82019-05-06 22:16:40 -070037 /* this defines the variable globally - not ideal, but works - see:
38 https://stackoverflow.com/questions/50571316/strange-variable-scoping-behavior-in-jenkinsfile
39 */
40 repos = sh(
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070041 returnStdout: true,
42 script: """
43 #!/usr/bin/env bash
44 set -eu -o pipefail
45
46 if [ -z "${github_organization}" ]
47 then
48 # no github org set, assume gerrit server
49 curl "${git_server_url}/projects/?pp=0" | python -c 'import json,sys; ij=sys.stdin.readlines(); obj=json.loads(ij[1]); print(",".join(obj.keys()))'
50 else
51 # github org set, assume github organization
52 curl -sS "https://api.github.com/orgs/${github_organization}/repos" | python -c 'import json,sys;obj=json.load(sys.stdin); print ",".join(map(lambda item: item["name"], obj))'
53 fi
Zack Williamsb92f5d82019-05-06 22:16:40 -070054 """
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070055 ).split(",")
Zack Williamsb92f5d82019-05-06 22:16:40 -070056 echo "repo list: ${repos}"
Zack Williamsc1d6a5e2019-05-06 16:35:58 -070057 }
58 }
59 }
60
61 stage ("Checkout repos") {
62 steps {
63 script {
64 repos.each { gitRepo ->
65 sh "echo Checking out: ${gitRepo}"
66 checkout(
67 [
68 $class: 'GitSCM',
69 userRemoteConfigs: [[
70 url: "${params.git_server_url}/${gitRepo}/",
71 name: "${branch}",
72 ]],
73 extensions: [
74 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${gitRepo}"],
75 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
76 ],
77 ])
78 }
79 }
80 }
81 }
82
83 stage ("Synopsys Detect") {
84 steps {
85 script {
86 repos.each { gitRepo ->
87 sh "echo Running Synopsys Detect on: ${gitRepo}"
88 synopsys_detect("--detect.source.path=${gitRepo} --detect.project.name=${blackduck_project} --detect.project.version.name=${branch} --detect.blackduck.signature.scanner.snippet.mode=true --detect.tools=ALL --detect.cleanup=false")
89 }
90 }
91 }
92 }
93
94 stage ("Save logs") {
95 steps {
96 sh returnStdout: true, script: """
97 echo COPYING LOGS
98 mkdir -p bd_logs
99 cp -r /home/jenkins/blackduck/runs/* bd_logs
100 ls -l bd_logs/*/*
101 """
102 archiveArtifacts artifacts:'bd_logs/**/*.*'
103 }
104 }
105 }
106}