This repository provides a modular and reusable Jenkins Shared Library to manage pipeline logic using Groovy and a class-based approach.
BasePipe
: Abstract base pipeline class that defines the structure and behavior for stage management.DoguPipe
: A concrete implementation tailored for Dogu builds.StageDefinition
: Data class for holding individual stage metadata.
Located in BasePipe.groovy
, this abstract class provides:
BasePipe(script)
Initializes the pipeline with a Jenkins script
context.
Adds a new stage to the pipeline.
agentLabel
: Optional agent label to execute the stage.parallel
: If true, this stage will be run in parallel with other stages on the same agent.
insertStageAfter(String afterName, String newName, Closure block, String agentLabel = defaultAgent, boolean parallel = false)
Inserts a stage after a given one.
overrideStage(String name, Closure newBlock, String newAgentLabel = null, Boolean newParallel = null)
Overrides an existing stage's logic or properties.
Removes a stage by name.
Reorders a stage after another stage.
Assigns or reassigns an agent to a stage.
Assigns multiple stages to different agents using a map.
Groups all added stages by their agent and:
- Executes sequential and parallel stages on the appropriate agents.
- Handles empty scripts or stage lists gracefully with debug logs.
Strips spaces and lowercases stage name for comparison.
Returns whether a stage exists.
Returns the StageDefinition
instance by name.
Found in StageDefinition.groovy
, used to represent each stage:
class StageDefinition {
String name
Closure block
String agentLabel
boolean parallel
}
DoguPipe.groovy
is a concrete subclass of BasePipe
tailored to build and release Dogu containers.
DoguPipe(script, Map config)
- Git, GitFlow, GitHub, EcoSystem, Vagrant, Markdown
- Customizable through the
config
map.
Adds a full set of predefined build/test/release stages.
executeShellTests()
: Runs Bats-based shell tests.runCypress()
: Runs Cypress integration tests.setBuildProperties(List customParams)
: Configures Jenkins parameters.checkout_updatemakefiles(boolean updateSubmodules)
: Checks out code and updates Makefiles with the latest version.
@Library('pipebuildlib') _
import com.cloudogu.sos.pipebuildlib.DoguPipe
def pipe = new DoguPipe(this, [
doguName: 'my-dogu',
runIntegrationTests: true,
shellScripts: 'scripts/*.sh'
])
pipe.setBuildProperties()
pipe.addDefaultStages()
pipe.run()
- Default agent label is
"sos"
if not specified. - Stages with the same agent can be grouped and run in parallel.
- Ensure your
Jenkinsfile
has access to the@Library
and the script context (this
) is passed correctly.
class MyCustomPipe extends BasePipe {
MyCustomPipe(script) {
super(script)
addStage("Checkout", {
script.echo "Checking out source..."
})
addStage("Build", {
script.echo "Building..."
}, agentLabel: "builder", parallel: false)
addStage("Test", {
script.echo "Running tests..."
}, parallel: true)
}
}
@Library('your-shared-library') _
def pipe = new MyCustomPipe(this)
pipe.run()
pipe.overrideStage("Build", {
script.echo "Overridden build step"
})
pipe.removeStage("Test")
pipe.insertStageAfter("Checkout", "Lint", {
script.echo "Linting code..."
})
@Library([
'pipe-build-lib',
'ces-build-lib',
'dogu-build-lib'
]) _
// Create instance of DoguPipe with configuration parameters
def pipe = new com.cloudogu.sos.pipebuildlib.DoguPipe(this, [
doguName : "jenkins",
// Optional behavior settings
shellScripts : "resources/startup.sh resources/upgrade-notification.sh resources/pre-upgrade.sh",
dependencies : ["cas", "usermgt"],
checkMarkdown : true,
runIntegrationTests: true,
cypressImage : "cypress/included:13.16.1"
])
// Set default or custom build parameters (can also pass a list to override defaults)
pipe.setBuildProperties()
// add default stages based on config map
pipe.addDefaultStages()
// Insert a custom post-integration stage directly after the "Integration Tests" stage
pipe.insertStageAfter("Integration Tests", "Test: Change Global Admin Group", {
def eco = pipe.ecoSystem
// Change the global admin group and restart jenkins
eco.changeGlobalAdminGroup("newAdminGroup")
eco.restartDogu("jenkins")
eco.waitForDogu("jenkins")
// Run Cypress tests again without video/screenshot recording
eco.runCypressIntegrationTests([
cypressImage : "cypress/included:13.16.1",
enableVideo : false,
enableScreenshots: false
])
})
// Run the pipeline – this will execute all previously added stages
pipe.run()