Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 1 | // Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 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 { |
You Wang | 20287cc | 2020-11-17 14:30:56 -0800 | [diff] [blame] | 22 | image "registry.aetherproject.org/ci/fossa-verify:latest" |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 23 | label "${params.buildNode}" |
You Wang | 20287cc | 2020-11-17 14:30:56 -0800 | [diff] [blame] | 24 | registryUrl "https://registry.aetherproject.org/" |
| 25 | registryCredentialsId "registry.aetherproject.org" |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | options { |
| 30 | timeout(15) |
| 31 | } |
| 32 | |
| 33 | stages { |
| 34 | |
| 35 | stage ("Clean Workspace") { |
| 36 | steps { |
| 37 | sh 'rm -rf *' |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | stage ("Checkout Pull Request") { |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 42 | when { |
| 43 | expression {return params.ghprbPullId != ""} |
| 44 | } |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 45 | steps { |
| 46 | checkout([ |
| 47 | $class: 'GitSCM', |
Jeremy Ronquillo | f86b836 | 2020-03-17 13:20:10 -0700 | [diff] [blame] | 48 | userRemoteConfigs: [[ url: "https://github.com/${params.ghprbGhRepository}", refspec: "pull/${params.ghprbPullId}/head" ]], |
| 49 | extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.project}"]], |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 50 | ], |
| 51 | ) |
| 52 | } |
| 53 | } |
| 54 | |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 55 | stage ("Checkout Repo (manual)") { |
| 56 | when { |
| 57 | expression {return params.ghprbPullId == ""} |
| 58 | } |
| 59 | steps { |
| 60 | checkout([ |
| 61 | $class: 'GitSCM', |
| 62 | userRemoteConfigs: [[ url: "https://github.com/${params.ghprbGhRepository}" ]], |
| 63 | extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${params.project}"]], |
| 64 | ], |
| 65 | ) |
| 66 | } |
| 67 | } |
| 68 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 69 | stage ("Perform License Scan") { |
| 70 | steps { |
| 71 | withCredentials([string(credentialsId: 'fossa-api-key', variable: 'FOSSA_API_KEY')]) { |
| 72 | sh """ |
| 73 | #!/usr/bin/env bash |
| 74 | |
Jeremy Ronquillo | f86b836 | 2020-03-17 13:20:10 -0700 | [diff] [blame] | 75 | cd ${params.project} |
Jeremy Ronquillo | a4e0cc2 | 2020-04-24 21:57:58 -0700 | [diff] [blame] | 76 | if [ ! -z ${params.ghprbPullId} ] |
Jeremy Ronquillo | 3ca065c | 2020-04-24 10:40:54 -0700 | [diff] [blame] | 77 | then |
| 78 | git checkout FETCH_HEAD |
| 79 | else |
| 80 | git checkout ${params.branch} |
| 81 | fi |
Jeremy Ronquillo | ae95dac | 2020-02-11 15:17:28 -0800 | [diff] [blame] | 82 | git show |
| 83 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 84 | echo "Testing project: ${params.project}" |
| 85 | |
Jeremy Ronquillo | 8df8e90 | 2020-04-29 15:16:11 -0700 | [diff] [blame] | 86 | if [ ! -f ".fossa.yml" ] |
| 87 | then |
| 88 | echo ".fossa.yml not found. This file is mandatory for the test to proceed." |
| 89 | exit 1 |
| 90 | fi |
| 91 | |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 92 | echo "Run 'fossa init'" |
| 93 | fossa init --no-ansi --verbose |
| 94 | |
| 95 | echo "Contents of .fossa.yml generated by 'fossa init':" |
| 96 | cat .fossa.yml |
| 97 | |
| 98 | echo "Run 'fossa analyze'" |
| 99 | fossa analyze --no-ansi --verbose |
| 100 | |
| 101 | echo "Get FOSSA test results with 'fossa test'" |
Jeremy Ronquillo | abd7bac | 2020-07-09 11:45:26 -0700 | [diff] [blame] | 102 | fossa test --no-ansi --verbose --timeout 1200 |
Jeremy Ronquillo | 77dc6c7 | 2020-03-02 15:59:04 -0800 | [diff] [blame] | 103 | |
| 104 | echo "Display list of licenses detected by FOSSA using 'fossa report licenses'" |
| 105 | fossa report licenses |
Jeremy Ronquillo | 9adc0a9 | 2020-01-29 10:49:45 -0800 | [diff] [blame] | 106 | """ |
| 107 | |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |