2016-07-21 18:38:38 +00:00
|
|
|
// Copyright 2016 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
def call(body) {
|
|
|
|
// evaluate the body block, and collect configuration into the object
|
|
|
|
def config = [:]
|
|
|
|
body.resolveStrategy = Closure.DELEGATE_FIRST
|
|
|
|
body.delegate = config
|
|
|
|
body()
|
|
|
|
|
|
|
|
// Mandatory configuration
|
|
|
|
def gitUrl = config["git"]
|
|
|
|
assert gitUrl : "git should be specified"
|
|
|
|
|
|
|
|
// Optional configuration
|
|
|
|
def projectName = config["name"] ?: env.JOB_BASE_NAME
|
2016-08-30 20:08:26 +00:00
|
|
|
def dockerfile = config["dockerfile"] ?: "oss-fuzz/$projectName/Dockerfile"
|
2016-08-12 00:02:20 +00:00
|
|
|
def sanitizers = config["sanitizers"] ?: ["address"]
|
2016-07-21 18:38:38 +00:00
|
|
|
def checkoutDir = config["checkoutDir"] ?: projectName
|
2016-08-01 21:21:46 +00:00
|
|
|
def dockerContextDir = config["dockerContextDir"]
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-08-12 00:13:19 +00:00
|
|
|
def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm")
|
|
|
|
.format(java.time.LocalDateTime.now())
|
2016-08-16 20:15:14 +00:00
|
|
|
def ossFuzzUrl = 'https://github.com/google/oss-fuzz.git'
|
2016-07-21 18:38:38 +00:00
|
|
|
|
|
|
|
node {
|
2016-10-10 20:20:59 +00:00
|
|
|
def workspace = pwd()
|
2016-10-10 20:28:03 +00:00
|
|
|
def revisionsFile = "$workspace/$projectName.rev"
|
2016-10-10 20:20:59 +00:00
|
|
|
def dockerTag = "ossfuzz/$projectName"
|
|
|
|
echo "Building $dockerTag"
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-10-10 20:20:59 +00:00
|
|
|
stage name: "docker image"
|
2016-10-10 20:23:35 +00:00
|
|
|
I:{ // groovy needs label for code block :)
|
2016-10-10 20:28:03 +00:00
|
|
|
def revisions = [:]
|
2016-08-01 21:14:13 +00:00
|
|
|
dir('oss-fuzz') {
|
2016-08-16 20:15:14 +00:00
|
|
|
git url: ossFuzzUrl
|
2016-08-01 21:14:13 +00:00
|
|
|
}
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-08-01 21:14:13 +00:00
|
|
|
dir(checkoutDir) {
|
|
|
|
git url: gitUrl
|
2016-08-16 20:15:14 +00:00
|
|
|
revisions[gitUrl] = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
|
2016-08-01 21:14:13 +00:00
|
|
|
}
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-08-01 21:21:46 +00:00
|
|
|
if (dockerContextDir == null) {
|
2016-08-01 21:46:50 +00:00
|
|
|
dockerContextDir = new File(dockerfile)
|
2016-08-01 21:44:02 +00:00
|
|
|
.getParentFile()
|
2016-08-01 21:46:50 +00:00
|
|
|
.getPath();
|
2016-08-01 21:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sh "docker build -t $dockerTag -f $dockerfile $dockerContextDir"
|
2016-10-10 20:28:03 +00:00
|
|
|
|
|
|
|
def revText = groovy.json.JsonOutput.toJson(revisions)
|
|
|
|
writeFile file: revisionsFile, text: revText
|
|
|
|
echo "revisions: $revText"
|
2016-10-10 20:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < sanitizers.size(); i++) {
|
|
|
|
def sanitizer = sanitizers[i]
|
|
|
|
dir(sanitizer) {
|
|
|
|
stage name: "$sanitizer sanitizer"
|
|
|
|
def out = "$workspace/out/$sanitizer"
|
|
|
|
|
2016-08-30 20:08:26 +00:00
|
|
|
// Run image to produce fuzzers
|
2016-07-21 18:38:38 +00:00
|
|
|
sh "rm -rf $out"
|
|
|
|
sh "mkdir -p $out"
|
2016-08-08 02:53:25 +00:00
|
|
|
sh "docker run -v $workspace/$checkoutDir:/src/$checkoutDir -v $workspace/oss-fuzz:/src/oss-fuzz -v $out:/out -e SANITIZER_FLAGS=\"-fsanitize=$sanitizer\" -t $dockerTag"
|
2016-08-30 20:22:34 +00:00
|
|
|
|
2016-08-30 20:08:26 +00:00
|
|
|
// Copy dict and options files
|
|
|
|
sh "cp $workspace/oss-fuzz/$projectName/*.dict $out/ || true"
|
|
|
|
sh "cp $workspace/oss-fuzz/$projectName/*.options $out/ || true"
|
2016-07-21 18:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 22:54:48 +00:00
|
|
|
|
2016-10-10 16:23:21 +00:00
|
|
|
// Run each of resulting fuzzers.
|
2016-08-11 22:54:48 +00:00
|
|
|
dir ('out') {
|
2016-10-10 20:20:59 +00:00
|
|
|
stage name: "running fuzzers"
|
2016-10-06 21:04:44 +00:00
|
|
|
sh "ls -alR"
|
2016-08-11 23:04:20 +00:00
|
|
|
for (int i = 0; i < sanitizers.size(); i++) {
|
|
|
|
def sanitizer = sanitizers[i]
|
|
|
|
dir (sanitizer) {
|
2016-08-11 23:22:10 +00:00
|
|
|
def d = pwd()
|
2016-08-11 23:04:20 +00:00
|
|
|
def files = findFiles()
|
|
|
|
for (int j = 0; j < files.size(); j++) {
|
|
|
|
def file = files[j]
|
2016-10-10 16:23:21 +00:00
|
|
|
if (file.directory) { continue }
|
2016-10-10 16:30:16 +00:00
|
|
|
if (!new File(d, file.name).canExecute()) {
|
2016-10-10 16:23:21 +00:00
|
|
|
echo "skipping: $file"
|
|
|
|
continue
|
2016-08-30 23:56:25 +00:00
|
|
|
}
|
2016-08-11 23:37:01 +00:00
|
|
|
sh "docker run -v $d:/out -t ossfuzz/libfuzzer-runner /out/$file -runs=1"
|
2016-08-11 23:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 22:54:48 +00:00
|
|
|
}
|
2016-08-12 00:13:19 +00:00
|
|
|
|
2016-10-10 20:20:59 +00:00
|
|
|
stage name: "uploading"
|
2016-08-12 00:13:19 +00:00
|
|
|
for (int i = 0; i < sanitizers.size(); i++) {
|
|
|
|
def sanitizer = sanitizers[i]
|
|
|
|
dir (sanitizer) {
|
2016-08-12 00:24:19 +00:00
|
|
|
def zipFile = "$projectName-$sanitizer-${date}.zip"
|
2016-08-16 20:15:14 +00:00
|
|
|
def revFile = "$projectName-$sanitizer-${date}.rev"
|
2016-10-10 20:28:03 +00:00
|
|
|
sh "cp $revisionsFile $revFile"
|
2016-08-12 00:22:14 +00:00
|
|
|
sh "zip -j $zipFile *"
|
2016-08-12 00:13:19 +00:00
|
|
|
sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
|
2016-08-16 20:15:14 +00:00
|
|
|
sh "gsutil cp $revFile gs://clusterfuzz-builds/$projectName/"
|
2016-08-12 00:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-06 21:26:09 +00:00
|
|
|
|
2016-10-10 20:20:59 +00:00
|
|
|
stage name: "pushing image"
|
2016-10-06 21:26:09 +00:00
|
|
|
docker.withRegistry('', 'docker-login') {
|
2016-10-10 20:20:59 +00:00
|
|
|
docker.image(dockerTag).push()
|
2016-10-06 21:26:09 +00:00
|
|
|
}
|
2016-08-11 22:54:48 +00:00
|
|
|
}
|
2016-07-21 18:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo 'Done'
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|