Skip to content

Commit

Permalink
Fail on config reload when config path is not set in jcasc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Richter committed Nov 13, 2018
1 parent 42ad25e commit 035f9ae
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions files/groovy/jcasc/reload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@


import groovy.json.JsonOutput
import io.jenkins.plugins.casc.ConfigurationAsCode
import io.jenkins.plugins.casc.*

CasCGlobalConfig config = GlobalConfiguration.all().get(CasCGlobalConfig.class)
String currentConfigPath = config.getConfigurationPath()

String msg = "Success"
Boolean failed = false

try {
ConfigurationAsCode.get().configure()
} catch (Exception ex) {
// set failed to yes
if (currentConfigPath != null) {
try {
ConfigurationAsCode.get().configure()
} catch (Exception ex) {
// set failed to yes
failed = true
msg = ex.toString()
}
} else {
// fail because no config path is set
failed = true
msg = ex.toString()
msg = "JCasC as currently no configuration path set! Reloading configuration skipped. Make sure to set a correct configuration path!"
}



def json = JsonOutput.toJson([
failed: failed,
msg: msg
])

return json.toString()
return json.toString()

0 comments on commit 035f9ae

Please sign in to comment.