From e18a536e730fd7653a880a983d9474c5e2fbeffa Mon Sep 17 00:00:00 2001 From: Aumkar Prajapati Date: Wed, 10 Oct 2018 09:21:57 -0400 Subject: [PATCH] Fixed lastBuild handling with habitat's new last_build.ps1 --- VERSION | 2 +- .../plugins/habitat/HabitatExecutor.java | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/VERSION b/VERSION index 0ea3a94..0c62199 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.0 +0.2.1 diff --git a/src/main/java/org/jenkinsci/plugins/habitat/HabitatExecutor.java b/src/main/java/org/jenkinsci/plugins/habitat/HabitatExecutor.java index f47e191..3ee8178 100644 --- a/src/main/java/org/jenkinsci/plugins/habitat/HabitatExecutor.java +++ b/src/main/java/org/jenkinsci/plugins/habitat/HabitatExecutor.java @@ -227,7 +227,7 @@ private String exportCommand(boolean isWindows, PrintStream log) throws Exceptio throw new Exception("Format entered is not valid! \n Valid formats: aci, cf, docker, kubernetes, mesos, tar"); } - String lastPackage = this.getLatestPackage(log); + String lastPackage = this.getLatestPackage(isWindows, log); if (!this.slave.call(new FileExistence(lastPackage))) { throw new Exception("Could not find hart file " + lastPackage); } @@ -249,7 +249,7 @@ private String binlinkCommand(boolean isWindows, PrintStream log) throws Excepti String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -293,7 +293,7 @@ private String searchCommand(boolean isWindows, PrintStream log) throws Exceptio private String promoteCommand(boolean isWindows, PrintStream log) throws Exception { String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -313,7 +313,7 @@ private String promoteCommand(boolean isWindows, PrintStream log) throws Excepti private String channelsCommand(boolean isWindows, PrintStream log) throws Exception { String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -328,7 +328,7 @@ private String channelsCommand(boolean isWindows, PrintStream log) throws Except private String configCommand(boolean isWindows, PrintStream log) throws Exception { String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -343,7 +343,7 @@ private String configCommand(boolean isWindows, PrintStream log) throws Exceptio private String execCommand(boolean isWindows, PrintStream log) throws Exception { String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -363,7 +363,7 @@ private String execCommand(boolean isWindows, PrintStream log) throws Exception private String demoteCommand(boolean isWindows, PrintStream log) throws Exception { String pkgIdent = this.getArtifact(); if (pkgIdent == null) { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); pkgIdent = lastBuild.getIdent(); } @@ -381,7 +381,7 @@ private String demoteCommand(boolean isWindows, PrintStream log) throws Exceptio private String uploadCommand(boolean isWindows, PrintStream log) throws Exception { - String lastPackage = this.getLatestPackage(log); + String lastPackage = this.getLatestPackage(isWindows, log); log.println("Last Package: " + lastPackage); if (!this.slave.call(new FileExistence(lastPackage))) { throw new Exception("Could not find hart " + lastPackage); @@ -393,9 +393,12 @@ private String uploadCommand(boolean isWindows, PrintStream log) throws Exceptio } } - private String getLatestPackage(PrintStream log) throws Exception { - LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(log))); + private String getLatestPackage(Boolean isWindows, PrintStream log) throws Exception { + LastBuild lastBuild = this.slave.call(new LastBuildSlaveRetriever(this.lastBuildPath(isWindows, log))); String artifact = lastBuild.getArtifact(); + if (isWindows) { + artifact = artifact.replace("\"", ""); + } log.println("Artifact " + artifact + " found in: " + this.getAbsolutePath(this.getDirectory())); return this.slave.call(new FileConstructor(Arrays.asList(this.getAbsolutePath(this.getDirectory()), artifact))); } @@ -404,11 +407,16 @@ private String getAbsolutePath(String file) throws IOException, InterruptedExcep return this.slave.call(new FilePathFinder(file)); } - private String lastBuildPath(PrintStream log) throws Exception { + private String lastBuildPath(boolean isWindows, PrintStream log) throws Exception { if (this.getLastBuildFile() != null) { if (this.getDirectory() == null) { String dir = this.getLastBuildFile(); - dir = dir.replace("last_build.env", ""); + if (isWindows) { + dir = dir.replace("last_build.ps1", ""); + } + else { + dir = dir.replace("last_build.env", ""); + } log.println("Setting Directory: " + dir); this.setDirectory(dir); }