@Test public void listener() throws Exception { logging.record( CpsFlowExecution.class, Level.WARNING).capture(200); String script = "node { \n" // + " echo \"hello\"\n" // + " " + "}"; WorkflowJob j = r.createProject( WorkflowJob.class, "listener" ); j.setDefinition( new CpsFlowDefinition( script, true ) ); Run run = r.buildAndAssertSuccess( j ); List<String> logs = logging.getMessages(); long found = logs.stream().filter( s -> s.contains( LOG_MESSAGE ) ).count(); Assert.assertTrue( "cannot find listener exception message", found > 0 ); }
@Test public void docker() throws Exception { StandardUsernamePasswordCredentials credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "ContainerExecDecoratorPipelineTest-docker", "bob", "username", "secret_password"); SystemCredentialsProvider.getInstance().getCredentials().add(credentials); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "docker"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("docker.groovy"), true)); containerExecLogs.capture(1000); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); assertNotNull(b); r.waitForCompletion(b); r.assertLogContains("Wrote authentication to /home/jenkins/.dockercfg", b); // check that we don't accidentally start exporting sensitive info to the build log r.assertLogNotContains("secret_password", b); // check that we don't accidentally start exporting sensitive info to the Jenkins log assertFalse("credential leaked to log", containerExecLogs.getMessages().stream().anyMatch(msg -> msg.contains("secret_password"))); } }