This step is the main step for building the feature/*
branches for
maven projects with Jenkins multibranch pipeline.
Basically the buildFeature
step calls the
buildDefault
step with a changed configuration.
💡 Have a look at the feature branch job tutorial.
The buildFeature
step support two modes depending on the groovy script
security and if the lib is running as a global trusted library or a
folder/project library.
Both modes change the configuration of the
defaultCompileStage
because featurebranch
artifacts should not be deployed to nexus!
The configuration adjustment is done by doing a merge with the incoming configuration. So you are still able to provide a custom maven configuration for the stage.
This is the default configuration passed to buildDefault
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
(STAGE_COMPILE) : [
(MAVEN) : [
(MAVEN_GOALS) : "clean install"
]
]
]
This mode is only working if the library is trusted or the belonging groovy calls are approved in script approval.
In this mode you just configure the SCM and the gredentials on the multibranch pipeline page.
The step will then read the scm
pipeline variable and transforms the
existing scm object into a Map based configuration which will then be
passed to buildDefault
and the nested checkoutScm
step.
The step will transform the following scm
properties into the scm configuration:
userRemoteConfigs
extensions
, currently supported:- CleanBeforeCheckout
- CleanCheckout
- PreBuildMerge
branches
submoduleCfg
doGenerateSubmoduleConfigurations
This step automatically adds:
- the
PreBuildMerge
extension to merge with the master
This mode is the "fallback" mode when Mode 1 was rejected by the Groovy Sandbox.
💡 In most cases this would be the mode used since running a library as global trusted can have negative side effects!
In this mode a scm configuration is added to tell the step
checkoutScm
that the existing scm
variable has to be used for checkout.
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
(SCM) : [
(SCM_USE_SCM_VAR) : true
],
(STAGE_COMPILE) : [
(MAVEN) : [
(MAVEN_GOALS) : "clean install"
]
]
]
This step supports the extension mechanism, so you are able to extend the step by executing code before and/or after the step is executed or even replacing the whole functionality.
💡 See _extend
for an example.
The buildFeature
step reuses the buildDefault
step with adjusted
configuration so please have a look at
buildDefault
configuration options
💡 Documentation about configuration
All configuration options for the buildFeature
stage must be inside
the
ConfigConstants.BUILD_FEATURE
map element to be evaluated and used by the step.
Constant | ConfigConstants.BUILD_FEATURE_EXTEND |
Type | Closure with signature (Map config, superImpl) |
Default | null |
Use this configuration option to overwrite or extend the buildFeature
step.
Example:
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
def customFeatureStage(Map config, superImpl) {
echo "before defaultFeature stage"
superImpl(config)
echo "after defaultFeature stage"
}
buildFeature(
(BUILD_FEATURE) : [
(BUILD_FEATURE_EXTEND) : this.&customFeatureStage
]
)