Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 1 | // Copyright 2020-present Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // omec-fossa-scan.groovy |
| 16 | // checks an omec-project repo against fossa in a docker container |
| 17 | |
| 18 | pipeline { |
| 19 | |
| 20 | agent { |
| 21 | docker { |
Jeremy Ronquillo | 9b65c60 | 2020-08-17 11:43:57 -0700 | [diff] [blame] | 22 | image "omecproject/fossa-verify:latest" |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 23 | label "${params.buildNode}" |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | options { |
| 28 | timeout(15) |
| 29 | } |
| 30 | |
| 31 | stages { |
| 32 | |
| 33 | stage ("Clean Workspace") { |
| 34 | steps { |
| 35 | sh 'rm -rf *' |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | stage ("Checkout Pull Request") { |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 40 | when { |
| 41 | expression {return params.ghprbPullId != ""} |
| 42 | } |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 43 | steps { |
| 44 | checkout([ |
| 45 | $class: 'GitSCM', |
Jeremy Ronquillo | f86b836 | 2020-03-17 13:20:10 -0700 | [diff] [blame] | 46 | userRemoteConfigs: [[ url: "https://github.com/${params.ghprbGhRepository}", refspec: "pull/${params.ghprbPullId}/head" ]], |
| 47 | extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.project}"]], |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 48 | ], |
| 49 | ) |
| 50 | } |
| 51 | } |
| 52 | |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 53 | stage ("Checkout Repo (manual)") { |
| 54 | when { |
| 55 | expression {return params.ghprbPullId == ""} |
| 56 | } |
| 57 | steps { |
| 58 | checkout([ |
| 59 | $class: 'GitSCM', |
| 60 | userRemoteConfigs: [[ url: "https://github.com/${params.ghprbGhRepository}" ]], |
| 61 | extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.project}"]], |
| 62 | ], |
| 63 | ) |
| 64 | } |
| 65 | } |
| 66 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 67 | stage ("Perform License Scan") { |
| 68 | steps { |
| 69 | withCredentials([string(credentialsId: 'fossa-api-key', variable: 'FOSSA_API_KEY')]) { |
| 70 | sh """ |
| 71 | #!/usr/bin/env bash |
| 72 | |
Jeremy Ronquillo | f86b836 | 2020-03-17 13:20:10 -0700 | [diff] [blame] | 73 | cd ${params.project} |
Jeremy Ronquillo | a4e0cc2 | 2020-04-24 21:57:58 -0700 | [diff] [blame] | 74 | if [ ! -z ${params.ghprbPullId} ] |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 75 | then |
| 76 | git checkout FETCH_HEAD |
| 77 | else |
| 78 | git checkout ${params.branch} |
| 79 | fi |
Jeremy Ronquillo | ae95dac | 2020-02-11 15:17:28 -0800 | [diff] [blame] | 80 | git show |
| 81 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 82 | echo "Testing project: ${params.project}" |
| 83 | |
Jeremy Ronquillo | 8df8e90 | 2020-04-29 15:16:11 -0700 | [diff] [blame] | 84 | if [ ! -f ".fossa.yml" ] |
| 85 | then |
| 86 | echo ".fossa.yml not found. This file is mandatory for the test to proceed." |
| 87 | exit 1 |
| 88 | fi |
| 89 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 90 | echo "Run 'fossa init'" |
| 91 | fossa init --no-ansi --verbose |
| 92 | |
| 93 | echo "Contents of .fossa.yml generated by 'fossa init':" |
| 94 | cat .fossa.yml |
| 95 | |
| 96 | echo "Run 'fossa analyze'" |
| 97 | fossa analyze --no-ansi --verbose |
| 98 | |
| 99 | echo "Get FOSSA test results with 'fossa test'" |
Jeremy Ronquillo | abd7bac | 2020-07-09 11:45:26 -0700 | [diff] [blame] | 100 | fossa test --no-ansi --verbose --timeout 1200 |
Jeremy Ronquillo | 77dc6c7 | 2020-03-02 15:59:04 -0800 | [diff] [blame] | 101 | |
| 102 | echo "Display list of licenses detected by FOSSA using 'fossa report licenses'" |
| 103 | fossa report licenses |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 104 | """ |
| 105 | |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |