BIGTOP-3148. Error out when configure-nexus encounter any issue (#456)
authorEvans Ye <evansye@apache.org>
Tue, 29 Jan 2019 08:41:13 +0000 (16:41 +0800)
committerGitHub <noreply@github.com>
Tue, 29 Jan 2019 08:41:13 +0000 (16:41 +0800)
build.gradle

index be1efe8..a925be0 100644 (file)
@@ -373,8 +373,25 @@ def generate_nexus_tasks = { name, url, snapshot ->
       write root.toString()
 
       workingDir '.'
-      commandLine  "curl", "-o", "/dev/null", "-X", "POST", "-d", "@$absolutePath",
+      commandLine  "curl", "-o", "/dev/null", "-s", "-w", "%{http_code}", "-X", "POST", "-d", "@$absolutePath",
         "--header", "Content-Type: application/json", "-u", "$_NEXUS_USERPASS", "$_NEXUS_URL/service/local/repositories"
+      standardOutput = new ByteArrayOutputStream()
+
+      doLast {
+        def httpCode = standardOutput.toString()
+        switch (httpCode) {
+          case "200":
+            println "Nexus proxy ${name} successfully configured"
+            break
+          case "400":
+            println "Skipped because Nexus proxy ${name} already configured"
+            break
+          default:
+            throw new GradleException("Failed to configure Nexus proxy ${name} with http code ${httpCode} returned. " +
+             "Run with --info option to see the executed command")
+            break
+        }
+      }
     }
   }
 }