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;
}
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;
}
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"));
}
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));
}
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();
}
Aggregations