liveBook · Manning

Jenkinsfile

As explained in Learn Docker in a Month of Lunches, Second Edition

A Jenkinsfile is a text file that defines the jobs or pipeline stages Jenkins executes for a project.

A Jenkinsfile keeps a project's CI job in source control beside its application, Dockerfiles, and Compose files. Its pipeline can call the same Docker Compose commands developers run locally, reducing differences between local builds and CI. section 11.4

Listing 11.5 Jenkinsfile build step that describes the CI job
# the build stage in the Jenkinsfile- it switches directory, then runs two
# shell commands - the first sets up a script file so it can be executed
# and the second calls the script:

stage('Build') {
  steps {
    dir('ch11/exercises') {
      sh 'chmod +x ./ci/01-build.bat'
      sh './ci/01-build.bat'
      }
  }
}

# and this is what's in 01-build.bat script:
docker compose
  -f docker-compose.yml
  -f docker-compose-build.yml
  build --pull

A build stage changes into the exercise directory, makes a script executable, and runs it; the script builds with Docker Compose and pulls current base images. section 11.4

A practical Jenkinsfile workflow includes:

  • Define a Build stage that invokes a small script rather than embedding every command directly. section 11.4
  • Run docker compose build --pull so CI uses the latest required base images and exposes breaking image changes early. section 11.4
  • Inspect Jenkins logs when a build fails; Docker Compose and Docker output is captured in the build step. section 11.4

Small CI lab

Complete a to-do application's pipeline by writing docker-compose-build.yml, creating a Jenkins job, and pointing it to the lab Jenkinsfile. Push the changes to Gogs, then inspect failed or successful builds and adjust the configuration. section 11.6

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Shows a concrete Build stage and delegated script, but stops short of detailing a complete multi-stage pipeline.
Examples
Uses a Docker Compose build script, Jenkins build logs, and a to-do application CI lab.
What it assumes
Assumes familiarity with Docker Compose commands and Jenkins job creation while supplying step-by-step configuration hints.
What you can do after
Builds a Jenkins job that runs Docker Compose through a source-controlled Jenkinsfile and diagnoses failures through captured logs.
How it connects
Connects Jenkinsfile with Jenkins, CI pipelines, Docker, Docker Compose, source control, and build logs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.