use of hudson.model.TaskListener in project nodejs-plugin by jenkinsci.
the class NodeJSCommandInterpreterTest method test_creation_of_config.
@Test
public void test_creation_of_config() throws Exception {
Config config = createSetting("my-config-id", "email=foo@acme.com", null);
NodeJSInstallation installation = mockInstaller();
NodeJSCommandInterpreter builder = CIBuilderHelper.createMock("test_creation_of_config", installation, config.id, new Verifier() {
@Override
public void verify(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws Exception {
EnvVars env = build.getEnvironment(listener);
String var = NodeJSConstants.NPM_USERCONFIG;
String value = env.get(var);
assertTrue("variable " + var + " not set", env.containsKey(var));
assertNotNull("empty value for environment variable " + var, value);
assertTrue("file of variable " + var + " does not exists or is not a file", new File(value).isFile());
}
});
FreeStyleProject job = j.createFreeStyleProject();
job.getBuildersList().add(builder);
j.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
use of hudson.model.TaskListener in project workflow-cps-plugin by jenkinsci.
the class DSL method reportMissingContextVariableException.
/**
* Reports a user-friendly error message for {@link MissingContextVariableException}.
*/
private void reportMissingContextVariableException(CpsStepContext context, MissingContextVariableException e) {
TaskListener tl;
try {
tl = context.get(TaskListener.class);
// if we can't report an error, give up
if (tl == null)
return;
} catch (IOException _) {
return;
} catch (InterruptedException _) {
return;
}
StringBuilder names = new StringBuilder();
for (StepDescriptor p : e.getProviders()) {
if (names.length() > 0)
names.append(',');
names.append(p.getFunctionName());
}
PrintStream logger = tl.getLogger();
logger.println(e.getMessage());
if (names.length() > 0)
logger.println("Perhaps you forgot to surround the code with a step that provides this, such as: " + names);
}
use of hudson.model.TaskListener in project pipeline-aws-plugin by jenkinsci.
the class CloudformationStackTests method noExecuteChangeSetIfNoChanges.
@Test
public void noExecuteChangeSetIfNoChanges() throws ExecutionException {
TaskListener taskListener = Mockito.mock(TaskListener.class);
Mockito.when(taskListener.getLogger()).thenReturn(System.out);
AmazonCloudFormation client = Mockito.mock(AmazonCloudFormation.class);
CloudFormationStack stack = new CloudFormationStack(client, "foo", taskListener);
Mockito.when(client.describeChangeSet(new DescribeChangeSetRequest().withStackName("foo").withChangeSetName("bar"))).thenReturn(new DescribeChangeSetResult());
stack.executeChangeSet("bar", 1000L);
Mockito.verify(client, Mockito.never()).executeChangeSet(Mockito.any(ExecuteChangeSetRequest.class));
}
use of hudson.model.TaskListener in project hudson-2.x by hudson.
the class ManagedWindowsServiceLauncher method launch.
@Override
public void launch(final SlaveComputer computer, final TaskListener listener) throws IOException, InterruptedException {
try {
final PrintStream logger = listener.getLogger();
final String name = determineHost(computer);
logger.println(Messages.ManagedWindowsServiceLauncher_ConnectingTo(name));
InetAddress host = InetAddress.getByName(name);
try {
Socket s = new Socket();
s.connect(new InetSocketAddress(host, 135), 5000);
s.close();
} catch (IOException e) {
logger.println("Failed to connect to port 135 of " + name + ". Is Windows firewall blocking this port? Or did you disable DCOM service?");
// again, let it continue.
}
JIDefaultAuthInfoImpl auth = createAuth();
JISession session = JISession.createSession(auth);
session.setGlobalSocketTimeout(60000);
SWbemServices services = WMI.connect(session, name);
String path = computer.getNode().getRemoteFS();
if (path.indexOf(':') == -1)
throw new IOException("Remote file system root path of the slave needs to be absolute: " + path);
SmbFile remoteRoot = new SmbFile("smb://" + name + "/" + path.replace('\\', '/').replace(':', '$') + "/", createSmbAuth());
if (!remoteRoot.exists())
remoteRoot.mkdirs();
try {
// does Java exist?
logger.println("Checking if Java exists");
WindowsRemoteProcessLauncher wrpl = new WindowsRemoteProcessLauncher(name, auth);
Process proc = wrpl.launch("java -fullversion", "c:\\");
proc.getOutputStream().close();
IOUtils.copy(proc.getInputStream(), logger);
proc.getInputStream().close();
int exitCode = proc.waitFor();
if (exitCode == 1) {
// we'll get this error code if Java is not found
// TODO enable me when JDK installer based on REST API will be ready
logger.println("No JDK found on slave node. Please install JDK");
throw new InterruptedException("No JDK found on slave node. Please install JDK");
// logger.println("No Java found. Downloading JDK");
// JDKInstaller jdki = new JDKInstaller("jdk-6u16-oth-JPR@CDS-CDS_Developer",true);
// URL jdk = jdki.locate(listener, Platform.WINDOWS, CPU.i386);
//
// listener.getLogger().println("Installing JDK");
// copyStreamAndClose(jdk.openStream(), new SmbFile(remoteRoot, "jdk.exe").getOutputStream());
//
// String javaDir = path + "\\jdk"; // this is where we install Java to
//
// WindowsRemoteFileSystem fs = new WindowsRemoteFileSystem(name, createSmbAuth());
// fs.mkdirs(javaDir);
//
// jdki.install(new WindowsRemoteLauncher(listener,wrpl), Platform.WINDOWS,
// fs, listener, javaDir ,path+"\\jdk.exe");
}
} catch (Exception e) {
e.printStackTrace(listener.error("Failed to prepare Java"));
}
String id = WindowsSlaveInstaller.generateServiceId(path);
Win32Service slaveService = services.getService(id);
if (slaveService == null) {
logger.println(Messages.ManagedWindowsServiceLauncher_InstallingSlaveService());
if (!DotNet.isInstalled(2, 0, name, auth)) {
// abort the launch
logger.println(Messages.ManagedWindowsServiceLauncher_DotNetRequired());
return;
}
// copy exe
logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveExe());
copyStreamAndClose(getClass().getResource("/windows-service/hudson.exe").openStream(), new SmbFile(remoteRoot, "hudson-slave.exe").getOutputStream());
copySlaveJar(logger, remoteRoot);
// copy hudson-slave.xml
logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveXml());
String xml = WindowsSlaveInstaller.generateSlaveXml(id, "javaw.exe", "-tcp %BASE%\\port.txt");
copyStreamAndClose(new ByteArrayInputStream(xml.getBytes("UTF-8")), new SmbFile(remoteRoot, "hudson-slave.xml").getOutputStream());
// install it as a service
logger.println(Messages.ManagedWindowsServiceLauncher_RegisteringService());
Document dom = new SAXReader().read(new StringReader(xml));
Win32Service svc = services.Get("Win32_Service").cast(Win32Service.class);
int r = svc.Create(id, dom.selectSingleNode("/service/name").getText() + " at " + path, path + "\\hudson-slave.exe", Win32OwnProcess, 0, "Manual", true);
if (r != 0) {
listener.error("Failed to create a service: " + svc.getErrorMessage(r));
return;
}
slaveService = services.getService(id);
} else {
copySlaveJar(logger, remoteRoot);
}
logger.println(Messages.ManagedWindowsServiceLauncher_StartingService());
slaveService.start();
// wait until we see the port.txt, but don't do so forever
logger.println(Messages.ManagedWindowsServiceLauncher_WaitingForService());
SmbFile portFile = new SmbFile(remoteRoot, "port.txt");
for (int i = 0; !portFile.exists(); i++) {
if (i >= 30) {
listener.error(Messages.ManagedWindowsServiceLauncher_ServiceDidntRespond());
return;
}
Thread.sleep(1000);
}
int p = readSmbFile(portFile);
// connect
logger.println(Messages.ManagedWindowsServiceLauncher_ConnectingToPort(p));
final Socket s = new Socket(name, p);
// ready
computer.setChannel(new BufferedInputStream(new SocketInputStream(s)), new BufferedOutputStream(new SocketOutputStream(s)), listener.getLogger(), new Listener() {
@Override
public void onClosed(Channel channel, IOException cause) {
afterDisconnect(computer, listener);
}
});
} catch (SmbException e) {
e.printStackTrace(listener.error(e.getMessage()));
} catch (JIException e) {
if (e.getErrorCode() == 5)
// access denied error
e.printStackTrace(listener.error(Messages.ManagedWindowsServiceLauncher_AccessDenied()));
else
e.printStackTrace(listener.error(e.getMessage()));
} catch (DocumentException e) {
e.printStackTrace(listener.error(e.getMessage()));
}
}
use of hudson.model.TaskListener in project sonar-scanner-jenkins by SonarSource.
the class LoggerTest method testFailureMessage.
@Test
public void testFailureMessage() {
TaskListener listener = mock(TaskListener.class);
PrintStream stream = mock(PrintStream.class);
when(listener.getLogger()).thenReturn(stream);
Logger.printFailureMessage(listener);
verify(stream).println("SONAR ANALYSIS FAILED");
}
Aggregations