Jenkinsfile in the Repo

Moving the Jenkinsfile into the Repository

By convention the file is named Jenkinsfile and sits at the repository root. BookNest's first one is short; the build, test and image stages join it in Building the Image:

Jenkinsfile at the root of booknest-jenkinsGroovy
// BookNest's pipeline, versioned with the code (Chapter 5)
pipeline {
  agent { label 'linux' }
  options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
    timeout(time: 15, unit: 'MINUTES')
  }
  stages {
    stage('Inspect') {
      steps {
        sh 'echo "Building $BRANCH_NAME at $(git rev-parse --short HEAD)"'
        sh 'test "$(grep -c \'"title"\' db/seed.json)" -eq 6'
      }
    }
  }
}

There is no git step: a pipeline loaded from SCM checks out the same commit it read the Jenkinsfile from, in an automatic Declarative: Checkout SCM stage (options { skipDefaultCheckout() } turns that off). Sam committed it to main as 2bcd495 "Add a Jenkinsfile for the multibranch pipeline" and pushed. A plain Pipeline job can also read it (Definition: Pipeline script from SCM), but only for one branch; the multibranch job does better.