The default build wrapper was introduced to increase reusability and reduce the amount of code to write in pipeline to get
- timestamps in console
- email- or instant messenger notifications
- build timeouts
- ssh agents
- scm polling
- log discarding
This step should be used as a wrapper for all custom pipeline scripts.
This step is also used by the buildDefault
step
In the first step the logger of the pipeline library is initialized.
The complete build is then wrapped inside a try and catch to enable
email notification when an exception like HudsonAbortException
is thrown.
The pipeline then gets a build timeout of 30 minutes.
After wrapping into the timeout wrapper the timestamps on the console output are enabled.
Then the default job properties are set by calling the
setJobProperties
step.
See setJobProperties for configuration options.
The defaultBuildWrapper
is able to wrap the closure with an ssh-agent.
import io.wcm.devops.jenkins.pipeline.ssh.SSHTarget
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
(BUILD_WRAPPER) : [
(BUILD_WRAPPER_SSH_TARGETS) : [ new SSHTarget("ssh-host.company.tld") ]
]
]
routeDefaultJenkinsFile(config)
See jenkins-pipeline-library sshAgentWrapper for details.
After the job properties are set the closure is called
Finally the wrapper calls the
steps and depending on configuration and build result notifications are send.
defaultBuildWrapper() {
echo "test"
}
This example
- configures the pipeline logger with
LogLevel.TRACE
- print the current workspace in the log
- Send a notification to [email protected] after every successful
build (and on the
notifyMail
default triggers)
import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
Map config = [
(LOGLEVEL) : LogLevel.TRACE,
(NOTIFY) : [
(NOTIFY_ON_SUCCESS) : true,
(NOTIFY_TO) : '[email protected]'
]
]
defaultBuildWrapper(config) {
node() {
sh 'pwd' // prints the current working directory
}
}
This example
- changes the build timeout to one hour
import java.util.concurrent.TimeUnit
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
import io.wcm.devops.jenkins.pipeline.utils.logging.LogLevel
Map config = [
(TIMEOUT) : [
(TIMEOUT_TIME) : 1,
(TIMEOUT_UNIT) : TimeUnit.HOURS
]
]
defaultBuildWrapper(config) {
node() {
sh 'pwd' // prints the current working directory
}
}
All configuration options must be inside the timeout
(ConfigConstants.TIMEOUT
)
or buildWrapper
(ConfigConstants.BUILD_WRAPPER
)
map element to be evaluated and used by the step.
import io.wcm.devops.jenkins.pipeline.ssh.SSHTarget
import java.util.concurrent.TimeUnit
import static de.provision.devops.jenkins.pipeline.utils.ConfigConstants.*
import static io.wcm.devops.jenkins.pipeline.utils.ConfigConstants.*
defaultBuildWrapper(
(TIMEOUT) : [
(TIMEOUT_TIME) : 30,
(TIMEOUT_UNIT) : TimeUnit.MINUTES
],
(BUILD_WRAPPER) : [
(BUILD_WRAPPER_SSH_TARGETS) : [ new SSHTarget("ssh-host.company.tld") ]
]
) {
// closure content
}
💡 The provided config map is also passed to
setJobProperties
Logger.init
notifyMail
default triggers)
Constant | ConfigConstants.TIMEOUT_TIME |
Type | Integer |
Default | 30 |
Use this configuration option to specify the integer component of the build timeout.
Constant | ConfigConstants.TIMEOUT_UNIT |
Type | java.util.concurrent.TimeUnit |
Default | TimeUnit.MINUTES |
Use this configuration option to specify the TimeUnit component of the build timeout.
Constant | ConfigConstants.BUILD_WRAPPER_SSH_TARGETS |
|
Type | List of io.wcm.devops.jenkins.pipeline.ssh.SSHTarget |
|
Default | [] |
Use this configuration option to specify a list of sshTarget to prepare
an ssh-agent for.
See jenkins-pipeline-library
sshAgentWrapper
for details (especially for the autolookup)