github.com/tw-bc-group/fabric-ca-gm@v0.0.0-20201218004200-3b690512bd5a/Jenkinsfile (about)

     1  def getRepoURL() {
     2    sh "git config --get remote.origin.url > .git/remote-url"
     3    return readFile(".git/remote-url").trim()
     4  }
     5  
     6  def projectName = "tw-bc-group/fabric-ca-gm"
     7  
     8  void setBuildStatus(String message, String state) {
     9    repoUrl = getRepoURL()
    10  
    11    step([
    12        $class: "GitHubCommitStatusSetter",
    13        reposSource: [$class: "ManuallyEnteredRepositorySource", url: repoUrl],
    14        contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
    15        errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
    16        statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
    17    ]);
    18  }
    19  
    20  pipeline {
    21      agent any
    22  
    23      environment {
    24          DOCKER_NS     = "${DOCKER_REGISTRY}/twbc"
    25          EXTRA_VERSION = "build-${BUILD_NUMBER}"
    26          GOPATH        = "${WORKSPACE}/gopath"
    27      }
    28  
    29      stages {
    30          stage('Build Image') {
    31              steps {
    32                  setBuildStatus("Build Started", "PENDING");
    33  
    34                  dir("gopath/src/github.com/$projectName") {
    35                      checkout scm
    36  
    37                      sh '''
    38                      make clean docker
    39                      '''
    40                  }
    41              }
    42          }
    43          stage('Upload Image') {
    44              steps {
    45                  dir("gopath/src/github.com/$projectName") {
    46                      sh 'aws ecr get-login-password | docker login --username AWS --password-stdin ${DOCKER_REGISTRY}'
    47                      sh '''
    48                      make docker-list 2>/dev/null | grep "$DOCKER_NS" | while read line
    49                      do
    50                         docker tag $line ${line/:*/:latest}
    51  
    52                         docker push $line
    53                         docker push ${line/:*/:latest}
    54  
    55                         docker rmi $line
    56                         docker rmi ${line/:*/:latest}
    57                      done
    58                      '''
    59                  }
    60              }
    61          }
    62  
    63          stage('Test Fabcar') {
    64              steps {
    65                  dir("gopath/src/github.com/$projectName") {
    66                      catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
    67                          script {
    68                              def result = build(
    69                                  job: 'fabric-sample-gm',
    70                                  propagate: false,
    71                                  parameters: [
    72                                      [$class: 'StringParameterValue', name: 'BYFN_CA', value: 'yes'],
    73                                      [$class: 'StringParameterValue', name: 'IMAGE_CA', value: sh(script: 'make fabric-ca-gm-docker-list 2>/dev/null ', returnStdout: true).trim()],
    74                                  ]
    75                              )
    76                              if (result.result.equals("SUCCESS")) {
    77                                  echo "Passed Test Fabcar"
    78                              } else {
    79                                  error "Failed Test Fabcar"
    80                              }
    81                          }
    82                      }
    83                  }
    84              }
    85          }
    86      }
    87  
    88      post {
    89          success {
    90              setBuildStatus("Build succeeded", "SUCCESS");
    91          }
    92          unsuccessful {
    93              setBuildStatus("Build failed", "FAILURE");
    94          }
    95      }
    96  }