This step is the main step for building the develop
and master
branch for maven projects with Jenkins pipeline.
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.
Inside the defaultBuildWrapper
a build node is allocated.
Inside the defaultBuildWrapper
and before the
defaultPreparationStage
it is possible
to place custom functionality. See preExtension
for
an example.
Inside the allocated node the
defaultPreparationStage
is used to
prepare the build of the project.
This step
- initializes the tools (JDK and maven) by using
setupPVTools
- checks out from SCM by using
checkoutScm
- sets the build name by using
setBuildName
- deletes maven snapshot artifacts from local maven repository by using
maven.purgeSnapshots
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
withclean 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
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
withcheckstyle:checkstyle pmd:pmd spotbugs:spotbugs -B
(defaults) - stashes files from the workspace after maven execution for later use (if enabled)
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
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.
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.
checkoutScm
config optionsdefaultAnalyzeStage
defaultCompileStage
defaultPreparationStage
- Logging configuration options
notifyMail
setupPVTools
💡 Documentation about configuration
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
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
]
]
)
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
]
]
)
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
]
]
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)
❗ 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)