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()
|
2016-11-29 19:09:12 +00:00
|
|
|
|
|
|
|
def project = new groovy.json.JsonSlurperClassic().parseText(config["project_json"])
|
|
|
|
|
2016-11-29 19:54:50 +00:00
|
|
|
// Project configuration.
|
2016-11-29 19:09:12 +00:00
|
|
|
def projectName = project["name"] ?: env.JOB_BASE_NAME
|
2016-11-29 19:54:50 +00:00
|
|
|
def sanitizers = project["sanitizers"] ?: ["address"]
|
2016-12-13 18:37:03 +00:00
|
|
|
def coverageFlags = project["coverage_flags"]
|
|
|
|
|
|
|
|
// Dockerfile config
|
2016-11-30 03:00:53 +00:00
|
|
|
def dockerfileConfig = project["dockerfile"] ?: [
|
2016-11-29 19:54:50 +00:00
|
|
|
"path": "projects/$projectName/Dockerfile",
|
|
|
|
"git" : "https://github.com/google/oss-fuzz.git",
|
|
|
|
"context" : "projects/$projectName/"
|
|
|
|
]
|
|
|
|
def dockerfile = dockerfileConfig["path"]
|
|
|
|
def dockerGit = dockerfileConfig["git"]
|
|
|
|
def dockerContextDir = dockerfileConfig["context"] ?: ""
|
|
|
|
def dockerTag = "ossfuzz/$projectName"
|
2016-12-21 23:01:44 +00:00
|
|
|
|
2016-11-23 17:24:13 +00:00
|
|
|
def date = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmm")
|
2016-12-29 22:37:10 +00:00
|
|
|
.format(java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC))
|
2016-07-21 18:38:38 +00:00
|
|
|
|
|
|
|
node {
|
2016-10-20 21:22:39 +00:00
|
|
|
def workspace = pwd()
|
|
|
|
def srcmapFile = "$workspace/srcmap.json"
|
2016-12-21 23:40:30 +00:00
|
|
|
def uid = sh(returnStdout: true, script: 'id -u $USER').trim()
|
|
|
|
def dockerRunOptions = "-e BUILD_UID=$uid --cap-add SYS_PTRACE"
|
2016-12-21 23:01:44 +00:00
|
|
|
|
2016-11-29 19:09:12 +00:00
|
|
|
echo "Building $dockerTag: $project"
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-12-13 21:08:51 +00:00
|
|
|
sh "docker run --rm $dockerRunOptions -v $workspace:/workspace ubuntu bash -c \"rm -rf /workspace/out\""
|
2016-10-20 21:22:39 +00:00
|
|
|
sh "mkdir -p $workspace/out"
|
2016-10-12 23:36:38 +00:00
|
|
|
|
2016-10-20 21:22:39 +00:00
|
|
|
stage("docker image") {
|
2016-11-29 19:54:50 +00:00
|
|
|
def dockerfileRev
|
2016-10-12 23:57:11 +00:00
|
|
|
|
2016-11-29 19:54:50 +00:00
|
|
|
dir('checkout') {
|
|
|
|
git url: dockerGit
|
|
|
|
dockerfileRev = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
|
2016-10-19 20:59:47 +00:00
|
|
|
}
|
2016-07-21 18:38:38 +00:00
|
|
|
|
2016-11-29 19:54:50 +00:00
|
|
|
sh "docker build --no-cache -t $dockerTag -f checkout/$dockerfile checkout/$dockerContextDir"
|
2016-10-19 20:59:47 +00:00
|
|
|
|
2016-11-29 19:54:50 +00:00
|
|
|
// obtain srcmap
|
2016-12-13 21:08:51 +00:00
|
|
|
sh "docker run $dockerRunOptions --rm $dockerTag srcmap > $workspace/srcmap.json.tmp"
|
2016-11-03 23:20:04 +00:00
|
|
|
// use classic slurper: http://stackoverflow.com/questions/37864542/jenkins-pipeline-notserializableexception-groovy-json-internal-lazymap
|
2016-11-03 23:17:19 +00:00
|
|
|
def srcmap = new groovy.json.JsonSlurperClassic().parse(
|
2016-11-03 20:50:21 +00:00
|
|
|
new File("$workspace/srcmap.json.tmp"))
|
2016-11-03 21:40:29 +00:00
|
|
|
srcmap['/src'] = [ type: 'git',
|
2016-11-29 19:54:50 +00:00
|
|
|
rev: dockerfileRev,
|
|
|
|
url: dockerGit,
|
2016-12-02 19:33:00 +00:00
|
|
|
path: "/" + dockerContextDir ]
|
2016-11-03 20:31:45 +00:00
|
|
|
echo "srcmap: $srcmap"
|
2016-11-04 04:43:44 +00:00
|
|
|
writeFile file: srcmapFile, text: groovy.json.JsonOutput.toJson(srcmap)
|
2016-10-20 21:22:39 +00:00
|
|
|
} // stage("docker image")
|
2016-08-11 22:54:48 +00:00
|
|
|
|
2016-10-20 21:22:39 +00:00
|
|
|
for (int i = 0; i < sanitizers.size(); i++) {
|
2016-10-10 20:36:13 +00:00
|
|
|
def sanitizer = sanitizers[i]
|
2016-10-20 21:22:39 +00:00
|
|
|
dir(sanitizer) {
|
|
|
|
def out = "$workspace/out/$sanitizer"
|
2016-10-26 21:22:20 +00:00
|
|
|
def junit_reports = "$workspace/junit_reports/$sanitizer"
|
|
|
|
sh "mkdir -p $out"
|
|
|
|
sh "mkdir -p $junit_reports"
|
2016-10-20 21:22:39 +00:00
|
|
|
stage("$sanitizer sanitizer") {
|
|
|
|
// Run image to produce fuzzers
|
2016-12-13 18:37:03 +00:00
|
|
|
def env = "-e SANITIZER=\"${sanitizer}\" "
|
|
|
|
if (coverageFlags != null) {
|
|
|
|
env += "-e COVERAGE_FLAGS=\"${coverageFlags}\" "
|
|
|
|
}
|
2016-12-13 21:08:51 +00:00
|
|
|
sh "docker run --rm $dockerRunOptions -v $out:/out $env -t $dockerTag compile"
|
2016-12-07 20:18:28 +00:00
|
|
|
// Test all fuzzers
|
2016-12-13 21:08:51 +00:00
|
|
|
sh "docker run --rm $dockerRunOptions -v $out:/out -v $junit_reports:/junit_reports -e TEST_SUITE=\"${projectName}.${sanitizer}.\" -t ossfuzz/base-runner test_report"
|
2016-10-10 20:36:13 +00:00
|
|
|
}
|
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:36:13 +00:00
|
|
|
stage("uploading") {
|
2016-10-27 17:03:49 +00:00
|
|
|
step([$class: 'JUnitResultArchiver', testResults: 'junit_reports/**/*.xml'])
|
2016-10-13 16:27:23 +00:00
|
|
|
dir('out') {
|
2016-10-20 21:22:39 +00:00
|
|
|
for (int i = 0; i < sanitizers.size(); i++) {
|
|
|
|
def sanitizer = sanitizers[i]
|
|
|
|
dir (sanitizer) {
|
|
|
|
def zipFile = "$projectName-$sanitizer-${date}.zip"
|
2016-12-20 22:47:40 +00:00
|
|
|
sh "zip -r $zipFile *"
|
2016-10-20 21:22:39 +00:00
|
|
|
sh "gsutil cp $zipFile gs://clusterfuzz-builds/$projectName/"
|
2016-10-20 21:39:55 +00:00
|
|
|
def stampedSrcmap = "$projectName-$sanitizer-${date}.srcmap.json"
|
|
|
|
sh "cp $srcmapFile $stampedSrcmap"
|
|
|
|
sh "gsutil cp $stampedSrcmap gs://clusterfuzz-builds/$projectName/"
|
2016-10-20 21:22:39 +00:00
|
|
|
}
|
2016-10-13 16:27:23 +00:00
|
|
|
}
|
2016-10-20 21:22:39 +00:00
|
|
|
}
|
|
|
|
} // stage("uploading")
|
2016-10-06 21:26:09 +00:00
|
|
|
|
2016-10-10 20:36:13 +00:00
|
|
|
stage("pushing image") {
|
2016-10-20 21:22:39 +00:00
|
|
|
docker.withRegistry('', 'docker-login') {
|
|
|
|
docker.image(dockerTag).push()
|
|
|
|
}
|
|
|
|
} // stage("pushing image")
|
|
|
|
} // node
|
|
|
|
} // call
|
2016-07-21 18:38:38 +00:00
|
|
|
|
|
|
|
return this;
|