github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-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      // Create a unique workspace so Jenkins doesn't reuse an existing one
    25      ws("workspace/${env.BUILD_TAG}") {
    26          stage("Clone Repo") {
    27              checkout scm
    28              sh 'git fetch --tag'
    29          }
    30  
    31          if (!(env.BRANCH_NAME == 'master' && env.JOB_BASE_NAME == 'master')) {
    32              stage("Check Whitelist") {
    33                  readTrusted 'bin/whitelist'
    34                  sh './bin/whitelist "$CHANGE_AUTHOR" /etc/jenkins-authorized-builders'
    35              }
    36          }
    37  
    38          stage("Check for Signed-Off Commits") {
    39              sh '''#!/bin/bash -l
    40                  if [ -v CHANGE_URL ] ;
    41                  then
    42                      temp_url="$(echo $CHANGE_URL |sed s#github.com/#api.github.com/repos/#)/commits"
    43                      pull_url="$(echo $temp_url |sed s#pull#pulls#)"
    44  
    45                      IFS=$'\n'
    46                      for m in $(curl -s "$pull_url" | grep "message") ; do
    47                          if echo "$m" | grep -qi signed-off-by:
    48                          then
    49                            continue
    50                          else
    51                            echo "FAIL: Missing Signed-Off Field"
    52                            echo "$m"
    53                            exit 1
    54                          fi
    55                      done
    56                      unset IFS;
    57                  fi
    58              '''
    59          }
    60  
    61          // Set the ISOLATION_ID environment variable for the whole pipeline
    62          env.ISOLATION_ID = sh(returnStdout: true, script: 'printf $BUILD_TAG | sha256sum | cut -c1-64').trim()
    63  
    64          // Use a docker container to build and protogen, so that the Jenkins
    65          // environment doesn't need all the dependencies.
    66          stage("Build Test Dependencies") {
    67              sh 'docker-compose -f docker-compose-installed.yaml build --force-rm'
    68          }
    69  
    70          stage("Create git archive") {
    71              sh '''
    72                  REPO=$(git remote show -n origin | grep Fetch | awk -F'[/.]' '{print $6}')
    73                  VERSION=`git describe --dirty`
    74                  git archive HEAD --format=zip -9 --output=$REPO-$VERSION.zip
    75                  git archive HEAD --format=tgz -9 --output=$REPO-$VERSION.tgz
    76              '''
    77          }
    78  
    79          stage ("Build documentation") {
    80              sh 'docker build . -f docs/supply-chain-build-docs -t supply-chain-build-docs:$ISOLATION_ID'
    81              sh 'docker run --rm -v $(pwd):/project/sawtooth-supply-chain supply-chain-build-docs:$ISOLATION_ID'
    82          }
    83  
    84          stage("Archive Build artifacts") {
    85              sh 'mkdir -p build/debs'
    86              sh 'docker run -v $(pwd)/build/debs:/build supply-tp-installed:$ISOLATION_ID bash -c "cp /tmp/supply-chain-tp*.deb /build"'
    87              archiveArtifacts artifacts: '*.tgz, *.zip'
    88              archiveArtifacts artifacts: 'build/debs/*.deb'
    89              archiveArtifacts artifacts: 'docs/build/html/**, docs/build/latex/*.pdf'
    90          }
    91      }
    92  }