Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Latest commit

 

History

History
384 lines (315 loc) · 11.2 KB

buildDefault.md

File metadata and controls

384 lines (315 loc) · 11.2 KB

buildDefault

This step is the main step for building the develop and master branch for maven projects with Jenkins pipeline.

Table of contents

Step sequence

Wrapping the build

This step wraps the complete build into the defaultBuildWrapper. The defaultBuildWrapper takes care about

  • initializing the logger
  • set build timeout
  • add timestamps to console output
  • set default job properties
    • scm polling
    • rebuild settings
  • wrapping the build into a try catch block
  • email notification

💡 Have a look at defaultBuildWrapper for more information.

Allocating node

Inside the defaultBuildWrapper a build node is allocated.

Call pre-execution Extensions

Inside the defaultBuildWrapper and before the defaultPreparationStage it is possible to place custom functionality. See preExtension for an example.

Prepare the build

Inside the allocated node the defaultPreparationStage is used to prepare the build of the project.

This step

Compile maven project

After preparation the project is build by using the defaultCompileStage.

This stage takes care about merging the maven defaults with project specific configuration (if set).

This step

  • calls execMaven with clean deploy -B -U (defaults)
  • stashes files from the workspace after maven execution for later use (if enabled)

💡 defaultCompileStage is also used during feature branch build but the maven goals are configured to clean install in this case since feature branches should not deploy to jenkins

Analyze maven project

After compiling the project it is analyzed by using the defaultAnalyzeStage

This stage takes care about merging the maven defaults with project specific configuration (if set).

This step

  • calls execMaven with checkstyle:checkstyle pmd:pmd spotbugs:spotbugs -B (defaults)
  • stashes files from the workspace after maven execution for later use (if enabled)
Publish Results

The last step called in the defaultBuild is the `defaultResultsStage

This stage processes and publishes the following build artifacts:

  • JUnit test reports
  • JaCoCo code coverage
  • findbugs result
  • pmd results
  • open tasks
  • checkstyle result
  • aggregate static analysis results
Call post-execution Extensions

Inside the defaultBuildWrapper and after the the defaultResultsStage](defaultResultsStage.md) it is possible to place custom functionality like deployment of the artifacts. See [postExtensions` for an example.

Configuration options

The configuration of this step is mostly build out of the config options from the used steps.

It mostly passes the config map to all config aware steps.

💡 Documentation about configuration

node

Constant ConfigConstants.NODE
Type String
Default null

Use this configuration option to specify a specific node/agent to build on.

Example:

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*

Map config = [
    (NODE) : 'unix && 64bit'
]
buildDefault(config)

See Using Agents from pipeline plugin tutorial for more information

preExtensions (optional)

Constant ConfigConstants.BUILD_DEFAULT_PRE_EXTENSIONS
Type List containing a list of closures
Default []

Use this configuration option to define steps that should run before the defaultPreparationStage.

💡 The passed function reference must have one parameter of type Map

Example:

import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*

def preStage1(Map config) {
  stage("preStage1") {
    echo "Hello World"  
  }
}

buildDefault(
  (BUILD_DEFAULT) : [
    (BUILD_DEFAULT_PRE_EXTENSIONS) : [
      this.&preStage1 
    ]
  ]
)

postExtensions (optional)

Constant ConfigConstants.BUILD_DEFAULT_POST_EXTENSIONS
Type List containing a list of closures
Default []

Use this configuration option to define steps that should run after the defaultResultsStage.

💡 The passed function reference must have one parameter of type Map

Example:

import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*

def postStage1(Map config) {
  stage("postStage1") {
    echo "Hello World"  
  }  
}

buildDefault(
  (BUILD_DEFAULT) : [
    (BUILD_DEFAULT_POST_EXTENSIONS) : [
      this.&postStage1 
    ]
  ]
)

Configuration structure

import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
[
    (BUILD_DEFAULT) : [
        (BUILD_DEFAULT_PRE_EXTENSIONS) : [],
        (BUILD_DEFAULT_POST_EXTENSIONS) : [],
    ],
    (LOGLEVEL) : LogLevel.INFO,
    (NODE) : null, // node expression to specify the used agent/slave
    (NOTIFY) : [
        // notify mail configuration options
    ],
    (SCM) : [
        // checkoutScm configuration options
    ],
    (STAGE_COMPILE) : [
        // compile stage configuration options
    ],
    (STAGE_ANALYZE) : [
        // analyze stage configuration options
    ],
    (TOOLS) : [
        // setupPVTools configuration options
    ]    
]

Default Configuration

The buildDefault runs with these defaults when

  • the SCM from the job is used.
  • no nodejs build was found

❗ This is just an example for the defaults. Please do not configure anything when you want to use the defaults!

import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
  (BUILD_DEFAULT) : [
    (BUILD_DEFAULT_PRE_EXTENSIONS) : [],
    (BUILD_DEFAULT_POST_EXTENSIONS) : [],
  ],
  (LOGLEVEL) : LogLevel.INFO,
  (NODE) : null,
  (NOTIFY) : [
    // step uses notification defaults     
  ],
  (SCM) : [        
    // scm is configured to use the existing scm var
    (SCM_USE_SCM_VAR) : true
  ],
  (PROPERTIES) : [
    (PROPERTIES_PIPELINE_TRIGGERS) : [
      pollSCM('H/15 * * * 0-6')
    ]
  ],
  (STAGE_COMPILE) : [
    // maven settings for compile stage
    (MAVEN) : [
      (MAVEN_GOALS) : ["clean","deploy"],
      (MAVEN_ARGUMENTS) : ["-B","-U"],
      (MAVEN_DEFINES) : ["continuousIntegration" : true]
    ],
    (STASH) : false, 
  ],
  (STAGE_ANALYZE) : [
    // maven settings for analyze stage
    (MAVEN) : [
      (MAVEN_GOALS) : ["checkstyle:checkstyle", "pmd:pmd", "spotbugs:spotbugs"],
      (MAVEN_ARGUMENTS) : ["-B" ],
      (MAVEN_DEFINES) : ["continuousIntegration" : true]
    ],
    (STASH) : false,        
  ],
  // default tools are retrieved from PipelineConfiguration
  /*
  (TOOLS) : [
    (TOOL_JDK) : "...",
    (TOOL_MAVEN) : "..."
  ]
  */    
]

routeDefaultJenkinsFile(config)

Complete configuration

❗ Not all configuration options can used together. This example gives just a complete overview of all possible configuration options

import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel

import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
    (LOGLEVEL) : LogLevel.INFO,
    (NOTIFY) : [
        // step uses notification defaults     
    ],
    (SCM) : [        
        // scm is configured to use the existing scm var
        (SCM_USE_SCM_VAR) : true
    ],
    (PROPERTIES) : [
        (PROPERTIES_PIPELINE_TRIGGERS) : [
            pollSCM('H/15 * * * 0-6')
        ]
    ],
    (STAGE_COMPILE) : [
        // maven settings for compile stage
        (MAVEN) : [
            (MAVEN_GOALS) : [ "clean", "deploy" ],
            (MAVEN_ARGUMENTS) : [ "-B", "-U" ],
            (MAVEN_DEFINES) : [ "continuousIntegration" : true ]
        ],
        (STASH) : false, 
    ],
    (STAGE_ANALYZE) : [
        // maven settings for analyze stage
        (MAVEN) : [
            (MAVEN_GOALS) : [ "checkstyle:checkstyle", "pmd:pmd", "spotbugs:spotbugs" ],
            (MAVEN_ARGUMENTS) : [ "-B" ],
            (MAVEN_DEFINES) : [ "continuousIntegration" : true ]
        ],
        (STASH) : false,        
    ],
    // default tools are retrieved from PipelineConfiguration
    /*
    (TOOLS) : [
        (TOOL_JDK) : "...",
        (TOOL_MAVEN) : "..."
    ]
    */   
]

routeDefaultJenkinsFile(config)

Related classes