Search in sources :

Example 1 with TaskListener

use of hudson.model.TaskListener 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 TaskListener

use of hudson.model.TaskListener 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)

Example 3 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method describeStack.

@Test
public void describeStack() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenReturn(new DescribeStacksResult().withStacks(new Stack().withOutputs(new Output().withOutputKey("bar").withOutputValue("baz"))));
    Assertions.assertThat(stack.describeOutputs()).isEqualTo(Collections.singletonMap("bar", "baz"));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method updateStack.

@Test
public void updateStack() throws ExecutionException {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    Mockito.when(taskListener.getLogger()).thenReturn(System.out);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    Mockito.when(client.waiters()).thenReturn(new AmazonCloudFormationWaiters(client));
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    stack.update("templateBody", null, Collections.<Parameter>emptyList(), Collections.<Tag>emptyList(), 25, "myarn");
    ArgumentCaptor<UpdateStackRequest> captor = ArgumentCaptor.forClass(UpdateStackRequest.class);
    Mockito.verify(client).updateStack(captor.capture());
    Assertions.assertThat(captor.getValue()).isEqualTo(new UpdateStackRequest().withStackName("foo").withTemplateBody("templateBody").withCapabilities(Capability.values()).withParameters(Collections.<Parameter>emptyList()).withRoleARN("myarn"));
    Mockito.verify(this.eventPrinter).waitAndPrintStackEvents(Mockito.eq("foo"), Mockito.any(Waiter.class), Mockito.eq(25L));
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Waiter(com.amazonaws.waiters.Waiter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with TaskListener

use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.

the class CloudformationStackTests method stackDoesNotExists.

@Test
public void stackDoesNotExists() {
    TaskListener taskListener = Mockito.mock(TaskListener.class);
    AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
    CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
    AmazonCloudFormationException ex = new AmazonCloudFormationException("foo");
    ex.setErrorCode("ValidationError");
    ex.setErrorMessage("stack foo does not exist");
    Mockito.when(client.describeStacks(new DescribeStacksRequest().withStackName("foo"))).thenThrow(ex);
    Assertions.assertThat(stack.exists()).isFalse();
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) TaskListener(hudson.model.TaskListener) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

TaskListener (hudson.model.TaskListener)28 Test (org.junit.Test)21 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 AmazonCloudFormationWaiters (com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters)10 Waiter (com.amazonaws.waiters.Waiter)9 EnvVars (hudson.EnvVars)6 IOException (java.io.IOException)4 Launcher (hudson.Launcher)3 LogTaskListener (hudson.util.LogTaskListener)3 PrintStream (java.io.PrintStream)3 FreeStyleProject (hudson.model.FreeStyleProject)2 GitException (hudson.plugins.git.GitException)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)2 GitClient (org.jenkinsci.plugins.gitclient.GitClient)2 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)1 Channel (hudson.remoting.Channel)1 Listener (hudson.remoting.Channel.Listener)1