HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How can I validate GoCD configuration before applying it

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
validatecangocdhowbeforeconfigurationapplying

Problem

We have a GoCD installation where we like to keep the pipeline configuration XML files (cruise-config.xml) in a separate git repository, and install it (preferably via a pipeline and automatically) to the GoCD server whenever it is changed.

However we couldn't find an easy way to validate the XML config file before sending it off to GoCD, and obviously we do't want to install invalid configs, as that would break our pipelines. Are there any tools, or utilities that help us with validating the config file?

Solution

The best solution we found so far, is using the MagicalGoConfigXmlLoader interface from the go source code, as it calls an internal validateCruiseConfig command, that does all validations, or die if the file is invalid:

MagicalGoConfigXmlLoader loader = new MagicalGoConfigXmlLoader(new ConfigCache());
loader.loadConfigHolder(configAsString);


The main problem with this solution that it essentially requires the whole GoCD server source code checked out, in a working state to work properly. Also as it's an internal API it is subject to changes between GoCD versions, making GoCD upgrades harder.

Code Snippets

MagicalGoConfigXmlLoader loader = new MagicalGoConfigXmlLoader(new ConfigCache());
loader.loadConfigHolder(configAsString);

Context

StackExchange DevOps Q#296, answer score: 4

Revisions (0)

No revisions yet.