I am working on a tool to automate mass-updating several pom files and pipeline files.
The pom files I am able to update and successfully push to bitbucket but am having an issue updating the yaml file as I don't see much of an option out there to update yaml files directly.
The pipeline yaml we have are quite big and I am wondering if there is a way to keep the same format of the existing pipeline file, sample :
build:
property1: .
property2: artifactory
property3: false
deploy:
property1: test
property2: test2
env:
property1: true
property2: '"template"'
I am able to successfully update the above yaml using the below code :
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
Map<String, Object> pipeline = objectMapper.readValue(
new File(DEFAULT_DIR + serviceName + "\\pipeline.yml"),
new TypeReference<Map<String, Object>>() {
});
Map<String, Object> build = (Map<String, Object>) pipeline.get("build");
build.put("property1", "d");
objectMapper.writeValue(new File(DEFAULT_DIR + serviceName + "\\pipeline.yml"), pipeline);
After writeValue creates the new yaml file, we see quotes around all the properties in the new yaml. I assume this is from the writeValue method from ObjectMapper.
build:
property1: "."
property2: "artifactory"
property3: false
deploy:
property1: "test"
property2: "test2"
env:
property1: true
property2: "\"template\""
Is this possible to keep the initial format of the yaml file without the quotes and the "\" \""
we are seeing after objectMapper writes the file? We have specific requirements for this layout in order for our Jenkins builds to work correctly.