Interview Prep/Jenkins/Declarative pipeline syntax

How do you load configuration files from the repo in a pipeline?

IntermediateConceptDeclarative pipeline syntax
Answer

With the Pipeline Utility Steps plugin:

script {
  def cfg  = readYaml file: 'deploy/config.yaml'
  def pkg  = readJSON file: 'package.json'
  def props = readProperties file: 'build.properties'
  env.APP_VERSION = pkg.version
  writeYaml file: 'out.yaml', data: cfg, overwrite: true
}

These run on the agent workspace but parse on the controller. Avoid readFile + JsonSlurper in pipeline code: JsonSlurper returns a non-serializable LazyMap.

All Jenkins questions Roadmap: Jenkins

More on Declarative pipeline syntax