Skip to content

Commit

Permalink
fix hugo command not execute problem
Browse files Browse the repository at this point in the history
add git rebase, in case of last push is failure
  • Loading branch information
LinuxSuRen committed May 17, 2018
1 parent 4c4176d commit 8810fc8
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/java/io/jenkins/plugins/hugo/HugoBuilder.java
Expand Up @@ -45,12 +45,12 @@ public class HugoBuilder extends Builder implements SimpleBuildStep
private String credentialsId;

private String hugoHome;
private String authorName;
private String authorEmail;
private String authorName = "hugo";
private String authorEmail = "hugo@hugo.com";
private String committerName;
private String committerEmail;

private String commitLog;
private String commitLog = "Auto commit by hugo-plugin.";

@DataBoundConstructor
public HugoBuilder(String credentialsId)
Expand Down Expand Up @@ -86,12 +86,19 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace,
FilePath publishPath = workspace.child(publishDir);

client = git.in(publishPath).getClient();
if(!client.hasGitRepo())
{
listener.error("Submodule has not init.");
return;
}

String branch = publishBranch;
logger.println("create new branch");

client.checkout().branch(branch).deleteBranchIfExist(true).ref("HEAD").execute();

client.rebase().setUpstream("origin/" + branch).execute();

logger.println("prepare to execute hugo");
hugoBuild(run, launcher, listener, workspace);

Expand All @@ -106,8 +113,16 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace,
if(credential != null)
{
client.setCredentials(credential);
client.setAuthor(getAuthorName(), getAuthorEmail());
client.setCommitter(getCommitterName(), getCommitterEmail());

if(getAuthorName() != null)
{
client.setAuthor(getAuthorName(), getAuthorEmail());
}

if(getCommitterName() != null)
{
client.setCommitter(getCommitterName(), getCommitterEmail());
}

logger.println("already set credential : " + credential.getUsername());
}
Expand All @@ -116,6 +131,10 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace,
logger.println("can not found credential");
}
}
else
{
logger.println("No credential provide.");
}

logger.println("remote is " + url);

Expand Down Expand Up @@ -165,7 +184,7 @@ private void hugoBuild(@Nonnull Run<?, ?> run, Launcher launcher, TaskListener l
hugoCmd = getHugoHome() + "hugo";
}

launcher.launch().cmds(hugoCmd).envs(env).stdout(logger).stderr(logger);
launcher.launch().pwd(workspace).cmds(hugoCmd).envs(env).stdout(logger).stderr(logger).start().join();
}

private StandardUsernameCredentials getCredential(PrintStream logger)
Expand Down

0 comments on commit 8810fc8

Please sign in to comment.