Search in sources :

Example 1 with LogTaskListener

use of hudson.util.LogTaskListener in project blueocean-plugin by jenkinsci.

the class GitCloneReadSaveRequest method cloneRepo.

GitClient cloneRepo() throws InterruptedException, IOException {
    EnvVars environment = new EnvVars();
    TaskListener taskListener = new LogTaskListener(Logger.getAnonymousLogger(), Level.ALL);
    String gitExe = gitTool.getGitExe();
    GitClient git = Git.with(taskListener, environment).in(repositoryPath).using(gitExe).getClient();
    git.addCredentials(gitSource.getRemote(), getCredential());
    try {
        git.clone(gitSource.getRemote(), "origin", true, null);
        log.fine("Repository " + gitSource.getRemote() + " cloned to: " + repositoryPath.getCanonicalPath());
    } catch (GitException e) {
        // check if this is an empty repository
        boolean isEmptyRepo = false;
        try {
            if (git.getRemoteReferences(gitSource.getRemote(), null, true, false).isEmpty()) {
                isEmptyRepo = true;
            }
        } catch (GitException ge) {
            // *sigh* @ this necessary hack; {@link org.jenkinsci.plugins.gitclient.CliGitAPIImpl#getRemoteReferences}
            if ("unexpected ls-remote output ".equals(ge.getMessage())) {
                // blank line, command succeeded
                isEmptyRepo = true;
            }
        // ignore other reasons
        }
        if (isEmptyRepo) {
            git.init();
            git.addRemoteUrl("origin", gitSource.getRemote());
            log.fine("Repository " + gitSource.getRemote() + " not found, created new to: " + repositoryPath.getCanonicalPath());
        } else {
            throw e;
        }
    }
    return git;
}
Also used : EnvVars(hudson.EnvVars) GitException(hudson.plugins.git.GitException) TaskListener(hudson.model.TaskListener) LogTaskListener(hudson.util.LogTaskListener) LogTaskListener(hudson.util.LogTaskListener) GitClient(org.jenkinsci.plugins.gitclient.GitClient)

Example 2 with LogTaskListener

use of hudson.util.LogTaskListener in project workflow-cps-plugin by jenkinsci.

the class EnvActionImpl method getEnvironment.

@Override
public EnvVars getEnvironment() throws IOException, InterruptedException {
    TaskListener listener;
    if (owner instanceof FlowExecutionOwner.Executable) {
        FlowExecutionOwner executionOwner = ((FlowExecutionOwner.Executable) owner).asFlowExecutionOwner();
        if (executionOwner != null) {
            listener = executionOwner.getListener();
        } else {
            listener = new LogTaskListener(LOGGER, Level.INFO);
        }
    } else {
        listener = new LogTaskListener(LOGGER, Level.INFO);
    }
    EnvVars e = owner.getEnvironment(listener);
    e.putAll(env);
    return e;
}
Also used : EnvVars(hudson.EnvVars) FlowExecutionOwner(org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner) LogTaskListener(hudson.util.LogTaskListener) TaskListener(hudson.model.TaskListener) LogTaskListener(hudson.util.LogTaskListener)

Aggregations

EnvVars (hudson.EnvVars)2 TaskListener (hudson.model.TaskListener)2 LogTaskListener (hudson.util.LogTaskListener)2 GitException (hudson.plugins.git.GitException)1 GitClient (org.jenkinsci.plugins.gitclient.GitClient)1 FlowExecutionOwner (org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner)1