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.
More on Declarative pipeline syntax
What is the minimum valid declarative pipeline?BeginnerWhat agent types exist in declarative pipelines?IntermediateWhen do you use `agent none` at the top level?IntermediateHow do nested sequential stages work and why are they useful?IntermediateList the `post` conditions and when each fires.IntermediateWhat are the most useful `when` conditions?Intermediate