github.com/xgoffin/jenkins-library@v1.154.0/vars/piperPipelineStageBuild.groovy (about)

     1  import com.sap.piper.ConfigurationHelper
     2  import com.sap.piper.GenerateStageDocumentation
     3  import com.sap.piper.StageNameProvider
     4  import com.sap.piper.Utils
     5  import groovy.transform.Field
     6  
     7  import static com.sap.piper.Prerequisites.checkScript
     8  
     9  @Field String STEP_NAME = getClass().getName()
    10  @Field String TECHNICAL_STAGE_NAME = 'build'
    11  
    12  @Field Set GENERAL_CONFIG_KEYS = []
    13  @Field STAGE_STEP_KEYS = [
    14      /** Starts build execution. This is always being executed.*/
    15      'buildExecute',
    16      /**
    17       * Executes stashing of files after build execution.<br /
    18       * Build results are stashed with stash name `buildResult`.
    19       *
    20       * **Note: Please make sure that your build artifacts are contained here since this stash is the foundation for subsequent tests and checks, e.g. deployment to a test landscape.**
    21       **/
    22      'pipelineStashFilesAfterBuild',
    23      /** Executes a Sonar scan.*/
    24      'sonarExecuteScan',
    25      /** Publishes test results to Jenkins. It will always be active. */
    26      'testsPublishResults',
    27      /** Publishes check results to Jenkins. It will always be active. */
    28      'checksPublishResults',
    29      /** Executes static code checks for Maven based projects. The plugins SpotBugs and PMD are used. */
    30      'mavenExecuteStaticCodeChecks',
    31      /** Executes linting for npm projects. */
    32      'npmExecuteLint'
    33  ]
    34  @Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS)
    35  @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
    36  
    37  /**
    38   * In this stage a build is executed which typically also executes tests and code checks.
    39   *
    40   * The type of build is defined using the configuration `buildTool`, see also step [buildExecute](../steps/buildExecute.md)
    41   *
    42   */
    43  @GenerateStageDocumentation(defaultStageName = 'Build')
    44  void call(Map parameters = [:]) {
    45  
    46      def script = checkScript(this, parameters) ?: this
    47      def utils = parameters.juStabUtils ?: new Utils()
    48      def stageName = StageNameProvider.instance.getStageName(script, parameters, this)
    49  
    50      Map config = ConfigurationHelper.newInstance(this)
    51          .loadStepDefaults()
    52          .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
    53          .mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
    54          .mixin(parameters, PARAMETER_KEYS)
    55          .addIfEmpty('npmExecuteLint', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.npmExecuteLint)
    56          .addIfEmpty('mavenExecuteStaticCodeChecks', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.mavenExecuteStaticCodeChecks)
    57          .use()
    58  
    59      piperStageWrapper (script: script, stageName: stageName) {
    60  
    61          // telemetry reporting
    62          utils.pushToSWA([step: STEP_NAME], config)
    63  
    64          durationMeasure(script: script, measurementName: 'build_duration') {
    65  
    66              buildExecute script: script
    67              pipelineStashFilesAfterBuild script: script
    68  
    69              try {
    70                  testsPublishResults script: script, junit: [updateResults: true]
    71                  checksPublishResults script: script
    72              } finally {
    73                  if (config.sonarExecuteScan) {
    74                      sonarExecuteScan script: script
    75                  }
    76              }
    77          }
    78  
    79          if (config.mavenExecuteStaticCodeChecks) {
    80              durationMeasure(script: script, measurementName: 'staticCodeChecks_duration') {
    81                  mavenExecuteStaticCodeChecks(script: script)
    82              }
    83          }
    84  
    85          if (config.npmExecuteLint) {
    86              durationMeasure(script: script, measurementName: 'npmExecuteLint_duration') {
    87                  npmExecuteLint script: script
    88              }
    89          }
    90      }
    91  }