Search⌘ K

Getting Rid of Repetition

Discover how to avoid code repetition in Jenkins X pipelines by using executable scripts instead of plugins or shared Groovy libraries. This lesson helps you understand the pipeline extension model's approach to streamlining pipeline code and improving maintainability across projects.

Copying and pasting code is a major sin among developers. One of the first things we learn as software engineers is that duplicated code is:

  • Hard to maintain.
  • Prone to errors.

That’s why we are creating libraries. We do not want to repeat ourselves, so we even came up with a commonly used acronym DRY (don’t repeat yourself).

With that in mind, all I can say is that Jenkins users are sinful.

Identical Jenkinsfile in projects

When we create pipelines through Jenkins (or almost any other similar tool), every project gets a Jenkinsfile based on the pipeline residing in the build pack we chose. If we have ten projects, there will be ten identical copies of the same Jenkinsfile. Over time, we’ll modify those Jenkinsfile ...