Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Declarative Jenkinsfile rewrite
Browse files Browse the repository at this point in the history
This change allows us to schedule automatic builds for the master
branch, excluding every open PR.

Signed-off-by: Richard Berg <[email protected]>
  • Loading branch information
rberg2 committed Apr 9, 2019
1 parent 2ca8ef0 commit 3c127d7
Showing 1 changed file with 69 additions and 39 deletions.
108 changes: 69 additions & 39 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,85 @@
// limitations under the License.
// ------------------------------------------------------------------------------

// Discard old builds after 31 days
properties([[$class: 'BuildDiscarderProperty', strategy:
[$class: 'LogRotator', artifactDaysToKeepStr: '',
artifactNumToKeepStr: '', daysToKeepStr: '31', numToKeepStr: '']]]);

node ('master') {
// Create a unique workspace so Jenkins doesn't reuse an existing one
ws("workspace/${env.BUILD_TAG}") {
stage("Clone Repo") {
checkout scm
pipeline {
agent {
node {
label 'master'
customWorkspace "workspace/${env.BUILD_TAG}"
}
}

triggers {
cron(env.BRANCH_NAME == 'master' ? 'H 3 * * *' : '')
}

options {
timestamps()
buildDiscarder(logRotator(daysToKeepStr: '31'))
}

environment {
ISOLATION_ID = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim()
COMPOSE_PROJECT_NAME = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim()
}

if (!(env.BRANCH_NAME == 'master' && env.JOB_BASE_NAME == 'master')) {
stage("Check Whitelist") {
stages {
stage('Check Whitelist') {
steps {
readTrusted 'bin/whitelist'
sh './bin/whitelist "$CHANGE_AUTHOR" /etc/jenkins-authorized-builders'
}
when {
not {
branch 'master'
}
}
}

stage('Check for Signed-Off Commits') {
steps {
sh '''#!/bin/bash -l
if [ -v CHANGE_URL ] ;
then
temp_url="$(echo $CHANGE_URL |sed s#github.com/#api.github.com/repos/#)/commits"
pull_url="$(echo $temp_url |sed s#pull#pulls#)"
IFS=$'\n'
for m in $(curl -s "$pull_url" | grep "message") ; do
if echo "$m" | grep -qi signed-off-by:
then
continue
else
echo "FAIL: Missing Signed-Off Field"
echo "$m"
exit 1
fi
done
unset IFS;
fi
'''
}
}

stage("Check for Signed-Off Commits") {
sh '''#!/bin/bash -l
if [ -v CHANGE_URL ] ;
then
temp_url="$(echo $CHANGE_URL |sed s#github.com/#api.github.com/repos/#)/commits"
pull_url="$(echo $temp_url |sed s#pull#pulls#)"
IFS=$'\n'
for m in $(curl -s "$pull_url" | grep "message") ; do
if echo "$m" | grep -qi signed-off-by:
then
continue
else
echo "FAIL: Missing Signed-Off Field"
echo "$m"
exit 1
fi
done
unset IFS;
fi
'''
stage('Fetch Tags') {
steps {
sh 'git fetch --tag'
}
}

// Set the ISOLATION_ID environment variable for the whole pipeline
env.ISOLATION_ID = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim()
stage('Build CXX SDK and Example TPs') {
steps {
sh 'docker build . -t sawtooth-sdk-cxx:$ISOLATION_ID'
sh 'docker run --rm -v $(pwd):/project/sawtooth-sdk-cxx sawtooth-sdk-cxx:$ISOLATION_ID'
}
}
}

// Use a docker container to build and protogen, so that the Jenkins
// environment doesn't need all the dependencies.
stage("Build CXX SDK and example TPs") {
sh 'docker build . -t sawtooth-sdk-cxx:$ISOLATION_ID'
sh 'docker run --rm -v $(pwd):/project/sawtooth-sdk-cxx sawtooth-sdk-cxx:$ISOLATION_ID'
post {
aborted {
error "Aborted, exiting now"
}
failure {
error "Failed, exiting now"
}
}
}

0 comments on commit 3c127d7

Please sign in to comment.