diff --git a/rd-cli-tool/src/main/java/org/rundeck/client/tool/commands/projects/SCM.java b/rd-cli-tool/src/main/java/org/rundeck/client/tool/commands/projects/SCM.java index 893e32f0..f013d4d0 100644 --- a/rd-cli-tool/src/main/java/org/rundeck/client/tool/commands/projects/SCM.java +++ b/rd-cli-tool/src/main/java/org/rundeck/client/tool/commands/projects/SCM.java @@ -120,7 +120,7 @@ static class FileOptions { } @CommandLine.Command(description = "Setup SCM Config for a Project") - public boolean setup( + public int setup( @CommandLine.Mixin BaseOpts opts, @CommandLine.Mixin TypeOptions typeOptions, @CommandLine.Mixin FileOptions fileOptions @@ -151,14 +151,14 @@ public boolean setup( "Setup config Validation for file: " + fileOptions.getFile().getAbsolutePath(), getRdTool().getAppConfig().isAnsiEnabled() )) { - return false; + return 2; } //otherwise check other error codes and fail if necessary ScmActionResult result = getRdTool().getClient().checkError(response); - return outputScmActionResult(getRdOutput(), result, "Setup"); + return outputScmActionResult(getRdOutput(), result, "Setup") ? 0 : 1; } private boolean outputScmActionResult(final CommandOutput output, final ScmActionResult result, final String name) { diff --git a/rd-cli-tool/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy b/rd-cli-tool/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy index 6dc91e27..eb5db499 100644 --- a/rd-cli-tool/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy +++ b/rd-cli-tool/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy @@ -391,4 +391,42 @@ class SCMSpec extends Specification { result==1 } + + @Unroll + def "setup exit code #expected for #desc"() { + given: + def api = Mock(RundeckApi) + def rdTool = setupMock(api) + def out = rdTool.getRdApp().getOutput() + def scm = new SCM() + scm.rdTool = rdTool + scm.rdOutput = out + + def baseopts = new SCM.BaseOpts() + baseopts.project = 'aproject' + baseopts.integration = 'import' + def typeOpts = new SCM.TypeOptions(type: 'git-import') + def tempFile = File.createTempFile('scm-setup', '.json') + tempFile.deleteOnExit() + tempFile.text = '{"config":{}}' + def fileOpts = new SCM.FileOptions(file: tempFile) + + when: + def result = scm.setup(baseopts, typeOpts, fileOpts) + + then: + 1 * api.setupScmConfig('aproject', 'import', 'git-import', _) >> response + result == expected + + where: + desc | expected | response + 'success' | 0 | Calls.response(new ScmActionResult(success: true)) + 'failure' | 1 | Calls.response(new ScmActionResult(success: false)) + 'validation error' | 2 | Calls.response( + Response.error(400, ResponseBody.create( + '{"message":"Error parsing JSON","success":false}', + Client.MEDIA_TYPE_JSON + )) + ) + } }