// Copyright (c) 2021-2022 Microchip Technology Inc. and its subsidiaries.
//
// Unpublished rights reserved under the copyright laws of the United States
// of America, other countries and international treaties. Permission to use,
// copy, store and modify, the software and its source code is granted but
// only in connection with products utilizing the Microsemi switch and PHY
// products.  Permission is also granted for you to integrate into other
// products, disclose, transmit and distribute the software only in an
// absolute machine readable format (e.g. HEX file) and only in or with
// products utilizing the Microsemi switch and PHY products.  The source code
// of the software may not be disclosed, transmitted or distributed without
// the prior written permission of Microsemi.
//
// This copyright notice must appear in any copy, modification, disclosure,
// transmission or distribution of the software.  Microsemi retains all
// ownership, copyright, trade secret and proprietary rights in the software
// and its source code, including all modifications thereto.
//
// THIS SOFTWARE HAS BEEN PROVIDED "AS IS". MICROSEMI HEREBY DISCLAIMS ALL
// WARRANTIES OF ANY KIND WITH RESPECT TO THE SOFTWARE, WHETHER SUCH
// WARRANTIES ARE EXPRESS, IMPLIED, STATUTORY OR OTHERWISE INCLUDING, WITHOUT
// LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR USE OR
// PURPOSE AND NON-INFRINGEMENT.

pipeline {
  agent {
    kubernetes {
      yamlFile '.kubernetespod.yaml'
    }
  }

  options {
      ansiColor('xterm')
  }

  environment {
      USER_NAME = "jenkins"
      BLD_USER = "jenkins"
      BLD_UID = "1000"
      top = "${env.WORKSPACE}"
      PATH = "${env.WORKSPACE}/scripts/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  }

  triggers{ cron(env.BRANCH_NAME == 'tfa.main' ? 'TZ=Europe/Copenhagen\n0 0 * * *' : '') }

  stages {
    stage('Prepare') {
      steps {
        echo "Buildcauses: ${currentBuild.getBuildCauses()}"

        // Old build folders may persist, and if there names are changing, then
        // they will never be cleaned up without this.
        sh 'git clean -qffdx'
      }
    }

    stage('Build TFA') {
      steps {
        container('tfa-builder') {
          sh "./scripts/platform_build.rb"
        }
      }
    }

    stage('Archive') {
      steps {
        archiveArtifacts artifacts: 'artifacts/**, keys/*'
      }
    }
  }

}
