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

Latest commit

 

History

History
211 lines (158 loc) · 8.88 KB

defaultPreparationStage.md

File metadata and controls

211 lines (158 loc) · 8.88 KB

defaultPreparationStage

The default preparation stage takes care about the basic job setup needed to build the project:

  • initialize needed build tools
  • checkout from scm
  • set the build name to a meaning name
  • delete project artifacts from local maven repository

Table of contents

Step sequence

Setup build tools

At first the tools needed for the maven build are initialized by using the setupPVTools step.

Checkout from scm

The code will then be checked out by using the checkoutScm step.

Set build name

After checkout the name of the build is set to a more meaningful name like

  • #1_origin/develop
  • #2_master

by using the setBuildName step.

Delete project maven artifacts from local repository

Since we always want to ensure that the build always uses the latest artifacts the project related maven artifacts are deleted from local repository by using the using maven.purgeSnapshots step.

Examples

Example 1: Use other maven and jdk

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

Map config = [
    (TOOLS) : [
        (TOOL_JDK) : "custom-jdk-installation",
        (TOOL_MAVEN) : "custom-maven-installation"
    ]
]

defaultPreparationStage(config)

Example 2: Configure scm checkout

This example will checkout develop and master branch from github with the LocalBranch extension.

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

Map config = [
    (SCM) : [
        (SCM_URL) : "https://github.com/wcm-io/wcm-io-wcm.git",
        (SCM_BRANCHES) : [[name: '*/master'], [name: '*/develop']],
        (SCM_EXTENSIONS) : [[$class: 'LocalBranch']]
    ]
]

defaultPreparationStage(config)

Extension options

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.

Configuration options

The provided configuration map object is passed to the steps that support configuration

The step itself supports the following configuration options.

All configuration options must be inside the preparationStage (ConfigConstants.STAGE_PREPARATION) map element to be evaluated and used by the step.

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

defaultPreparationStage( 
    (STAGE_PREPARATION) : [
        (STAGE_PREPARATION_CHECKOUT_SCM): true,
        (STAGE_PREPARATION_EXTEND) : null,
        (STAGE_PREPARATION_PURGE_SHAPSHOTS): true,
        (STAGE_PREPARATION_SET_BUILD_NAME): true,
        (STAGE_PREPARATION_SETUP_TOOLS): true,
        (STAGE_PREPARATION_STAGE_WRAP): true
    ]
)

_extend (optional)

Constant ConfigConstants.STAGE_PREPARATION_EXTEND
Type Closure with signature (Map config, superImpl)
Default null

Use this configuration option to overwrite or extend the defaultPreparationStage step.

Example:

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

def customPreparationStage(Map config, superImpl) {
  echo "before defaultPreparationStage stage"
  superImpl(config)
  echo "after defaultPreparationStage stage"
}

defaultCompileStage(
  (STAGE_PREPARATION) : [
    (STAGE_PREPARATION_EXTEND) : this.&customPreparationStage
  ]
)

checkoutScm (optional)

Constant ConfigConstants.STAGE_PREPARATION_CHECKOUT_SCM
Type Boolean
Default true

Controls if checkout from scm is executed.

purgeSnapshots (optional)

Constant ConfigConstants.STAGE_PREPARATION_PURGE_SHAPSHOTS
Type Boolean
Default true

Controls if maven snapshots are purged from the local repository.

setBuildName (optional)

Constant ConfigConstants.STAGE_PREPARATION_SET_BUILD_NAME
Type Boolean
Default true

Controls if build name is updated.

setupTools (optional)

Constant ConfigConstants.STAGE_PREPARATION_SETUP_TOOLS
Type Boolean
Default true

Controls if tool setup is executed.

stageWrap (optional)

Constant ConfigConstants.STAGE_PREPARATION_STAGE_WRAP
Type Boolean
Default true

Controls if the steps are wrapped into a stage named "Preparation". Can be useful in declarative pipelines.