github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/build/Jenkinsfile.branch (about)

     1  #!/usr/bin/env groovy
     2  
     3  @Library('shared-pipelines') _
     4  import org.mattermost.Utils
     5  import java.util.*;
     6  def utils = new org.mattermost.Utils()
     7  def build = new org.mattermost.BuildCommands()
     8  def platformStages = new org.mattermost.PlatformStages()
     9  
    10  def rndEE = UUID.randomUUID().toString()
    11  def rndTE = UUID.randomUUID().toString()
    12  def mmBuilderServer = 'mattermost/mattermost-build-server:20200322_golang-1.14.1'
    13  def mmBuilderWebapp = 'mattermost/mattermost-build-webapp:oct-2-2018'
    14  
    15  pipeline {
    16    agent {
    17      label 'default-mm-builder'
    18    }
    19  
    20    options {
    21      buildDiscarder(logRotator(daysToKeepStr: '15'))
    22      timeout(time: 2, unit: 'HOURS')
    23    }
    24  
    25    environment {
    26      COMPOSE_PROJECT_NAME="${rnd}-${env.BUILD_NUMBER}"
    27      GOPATH = "/go"
    28    }
    29  
    30    stages {
    31      stage('Setup') {
    32        steps {
    33          script {
    34            platformStages.platformEcho()
    35          }
    36        }
    37      }
    38  
    39      stage('Build') {
    40        failFast true
    41        parallel {
    42          stage ('Build EE') {
    43            agent {
    44              label 'default-mm-builder'
    45            }
    46            steps {
    47              script {
    48                forcefullyCleanWorkspace(mmBuilderServer)
    49                platformStages.platformCheckoutTE(env.BRANCH_NAME)
    50                platformStages.platformCheckoutEE(env.BRANCH_NAME)
    51                platformStages.platformCheckoutRedux(env.BRANCH_NAME)
    52                SERVER_GIT_COMMIT=platformStages.platformServerCommitHash()
    53                try {
    54                  platformStages.after5Dot20AddGOBINBuild(env.BRANCH_NAME + '.' + env.BUILD_NUMBER + '.' + SERVER_GIT_COMMIT, rndEE, false, mmBuilderServer, mmBuilderWebapp)
    55                } finally {
    56                  platformStages.platformPublishResults()
    57                  platformStages.platformCleanDockerCompose(rndEE)
    58                }
    59              }
    60              stash includes: 'src/github.com/vnforks/kid/dist/**', name: 'eedist'
    61            }
    62          }
    63          stage ('Build TE') {
    64            agent {
    65              label 'default-mm-builder'
    66            }
    67            steps {
    68              script {
    69                forcefullyCleanWorkspace(mmBuilderServer)
    70                platformStages.platformCheckoutTE(env.BRANCH_NAME)
    71                platformStages.platformCheckoutRedux(env.BRANCH_NAME)
    72                SERVER_GIT_COMMIT=platformStages.platformServerCommitHash()
    73                try {
    74                  platformStages.after5Dot20AddGOBINBuild(env.BRANCH_NAME + '.' + env.BUILD_NUMBER + '.' + SERVER_GIT_COMMIT, rndTE, false, mmBuilderServer, mmBuilderWebapp)
    75                } finally {
    76                  platformStages.platformPublishResults()
    77                  platformStages.platformCleanDockerCompose(rndTE)
    78                }
    79              }
    80              stash includes: 'src/github.com/vnforks/kid/dist/**', name: 'tedist'
    81            }
    82          }
    83        }
    84      }
    85  
    86      stage ('Push EE') {
    87        steps {
    88          node('master') {
    89            forcefullyCleanWorkspace(mmBuilderServer)
    90            unstash 'eedist'
    91            script {
    92              platformStages.pushToS3('mattermost-platform/' + env.BRANCH_NAME, 'mattermost-enterprise-*',false)
    93            }
    94          }
    95        }
    96      }
    97      stage ('Push TE') {
    98        steps {
    99          node('master') {
   100            forcefullyCleanWorkspace(mmBuilderServer)
   101            unstash 'tedist'
   102            script {
   103              platformStages.pushToS3('mattermost-platform/' + env.BRANCH_NAME, 'mattermost-branch-*',false)
   104            }
   105          }
   106        }
   107      }
   108      stage ('CleanCloudfront') {
   109        steps {
   110          node('master') {
   111            script {
   112              platformStages.cleanCloudfrontCache('mattermost-platform/' + env.BRANCH_NAME)
   113            }
   114          }
   115        }
   116      }
   117  
   118      stage ('Build Docker Images') {
   119        agent {
   120          label 'default-mm-builder'
   121        }
   122        steps {
   123          script {
   124            forcefullyCleanWorkspace(mmBuilderServer)
   125            platformStages.platformCheckoutTE(env.BRANCH_NAME)
   126          }
   127          dir('src/github.com/vnforks/kid') {
   128            withCredentials([usernamePassword(credentialsId: 'matterbuild-docker-hub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
   129              sh 'docker login --username ${DOCKER_USER} --password ${DOCKER_PASS}'
   130              sh """
   131              export TAG='${env.BRANCH_NAME}'
   132              docker build --no-cache --build-arg MM_PACKAGE=https://releases.mattermost.com/mattermost-platform/${env.BRANCH_NAME}/mattermost-enterprise-linux-amd64.tar.gz -t mattermost/mattermost-enterprise-edition:\${TAG} build
   133              docker push mattermost/mattermost-enterprise-edition:\${TAG}
   134              """
   135              sh """
   136              export TAG='${env.BRANCH_NAME}'
   137              docker build --no-cache --build-arg MM_PACKAGE=https://releases.mattermost.com/mattermost-platform/${env.BRANCH_NAME}/mattermost-branch-linux-amd64.tar.gz -t mattermost/mattermost-branch-edition:\${TAG} build
   138              docker push mattermost/mattermost-branch-edition:\${TAG}
   139              docker logout
   140              """
   141            }
   142          }
   143        }
   144      }
   145    }
   146  
   147    post {
   148      cleanup {
   149        forcefullyCleanWorkspace(mmBuilderServer)
   150      }
   151    }
   152  }
   153  
   154  
   155  def forcefullyCleanWorkspace(String imageToUse) {
   156    return withDockerContainer(
   157      image: imageToUse,
   158      args: '-u root'
   159    ) {
   160      ansiColor('xterm') {
   161        sh """#!/bin/bash -e
   162          if [ -d "\$WORKSPACE" ]
   163          then
   164            rm -rfv \$WORKSPACE/*
   165          fi
   166        """
   167      }
   168    }
   169  }