github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/Jenkinsfile (about) 1 #!groovy 2 3 // Copyright 2017 Intel Corporation 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ------------------------------------------------------------------------------ 17 18 // Discard old builds after 31 days 19 properties([[$class: 'BuildDiscarderProperty', strategy: 20 [$class: 'LogRotator', artifactDaysToKeepStr: '', 21 artifactNumToKeepStr: '', daysToKeepStr: '31', numToKeepStr: '']]]); 22 23 node ('master') { 24 timestamps { 25 // Create a unique workspace so Jenkins doesn't reuse an existing one 26 ws("workspace/${env.BUILD_TAG}") { 27 stage("Clone Repo") { 28 checkout scm 29 sh 'git fetch --tag' 30 } 31 32 if (!(env.BRANCH_NAME == 'master' && env.JOB_BASE_NAME == 'master')) { 33 stage("Check Whitelist") { 34 readTrusted 'bin/whitelist' 35 sh './bin/whitelist "$CHANGE_AUTHOR" /etc/jenkins-authorized-builders' 36 } 37 } 38 39 stage("Check for Signed-Off Commits") { 40 sh '''#!/bin/bash -l 41 if [ -v CHANGE_URL ] ; 42 then 43 temp_url="$(echo $CHANGE_URL |sed s#github.com/#api.github.com/repos/#)/commits" 44 pull_url="$(echo $temp_url |sed s#pull#pulls#)" 45 46 IFS=$'\n' 47 for m in $(curl -s "$pull_url" | grep "message") ; do 48 if echo "$m" | grep -qi signed-off-by: 49 then 50 continue 51 else 52 echo "FAIL: Missing Signed-Off Field" 53 echo "$m" 54 exit 1 55 fi 56 done 57 unset IFS; 58 fi 59 ''' 60 } 61 62 // Set the ISOLATION_ID environment variable for the whole pipeline 63 env.ISOLATION_ID = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim() 64 env.COMPOSE_PROJECT_NAME = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim() 65 66 // Use a docker container to build and protogen, so that the Jenkins 67 // environment doesn't need all the dependencies. 68 69 stage("Build Lint Requirements") { 70 sh 'docker-compose -f docker/compose/run-lint.yaml build' 71 sh 'docker-compose -f docker/compose/sawtooth-build.yaml up' 72 sh 'docker-compose -f docker/compose/sawtooth-build.yaml down' 73 } 74 75 stage("Run Lint") { 76 sh 'docker-compose -f docker/compose/run-lint.yaml up --abort-on-container-exit --exit-code-from lint-python lint-python' 77 sh 'docker-compose -f docker/compose/run-lint.yaml up --abort-on-container-exit --exit-code-from lint-go lint-go' 78 sh 'docker-compose -f docker/compose/run-lint.yaml up --abort-on-container-exit --exit-code-from lint-rust lint-rust' 79 sh 'docker-compose -f docker/compose/run-lint.yaml up --abort-on-container-exit --exit-code-from lint-validator lint-validator' 80 } 81 82 stage("Build Test Dependencies") { 83 sh 'docker-compose -f docker-compose-installed.yaml build' 84 sh 'docker-compose -f docker/compose/external.yaml build' 85 sh 'docker build -f docker/bandit -t bandit:$ISOLATION_ID .' 86 } 87 88 stage("Run Bandit") { 89 sh 'docker run --rm -v $(pwd):/project/sawtooth-core bandit:$ISOLATION_ID run_bandit' 90 } 91 92 // Run the tests 93 stage("Run Tests") { 94 sh 'INSTALL_TYPE="" ./bin/run_tests -i deployment' 95 } 96 97 stage("Compile coverage report") { 98 sh 'docker run --rm -v $(pwd):/project/sawtooth-core integration-tests:$ISOLATION_ID /bin/bash -c "cd coverage && coverage combine && coverage html -d html"' 99 } 100 101 stage("Create git archive") { 102 sh ''' 103 REPO=$(git remote show -n origin | grep Fetch | awk -F'[/.]' '{print $6}') 104 VERSION=`git describe --dirty` 105 git archive HEAD --format=zip -9 --output=$REPO-$VERSION.zip 106 git archive HEAD --format=tgz -9 --output=$REPO-$VERSION.tgz 107 ''' 108 } 109 110 stage ("Build documentation") { 111 sh 'docker build . -f ci/sawtooth-build-docs -t sawtooth-build-docs:$ISOLATION_ID' 112 sh 'docker run --rm -v $(pwd):/project/sawtooth-core sawtooth-build-docs:$ISOLATION_ID' 113 } 114 115 stage("Archive Build artifacts") { 116 sh 'docker-compose -f docker/compose/copy-debs.yaml up' 117 archiveArtifacts artifacts: '*.tgz, *.zip' 118 archiveArtifacts artifacts: 'build/debs/*.deb' 119 archiveArtifacts artifacts: 'build/bandit.html' 120 archiveArtifacts artifacts: 'coverage/html/*' 121 archiveArtifacts artifacts: 'docs/build/html/**, docs/build/latex/*.pdf' 122 sh 'docker-compose -f docker/compose/copy-debs.yaml down' 123 } 124 } 125 } 126 }