Skip to content

Commit

Permalink
Fixed lastBuild handling with habitat's new last_build.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
Aumkar Prajapati committed Oct 10, 2018
1 parent 5a0bd8d commit e18a536
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.0
0.2.1
32 changes: 20 additions & 12 deletions src/main/java/org/jenkinsci/plugins/habitat/HabitatExecutor.java
Expand Up @@ -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);
}
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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);
Expand All @@ -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)));
}
Expand All @@ -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);
}
Expand Down

0 comments on commit e18a536

Please sign in to comment.