Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ public void basicsPipeline() throws Exception {
String alias = "androiddebugkey";
String password = "android";
StandardCertificateCredentials c = new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "my-certificate", alias,
password, new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(certificate.getAbsolutePath()));
password, new CertificateCredentialsImpl.UploadedKeyStoreSource(new FileParameterValue.FileItemImpl(certificate), null));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix

CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
// create the Pipeline job
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
String pipelineScript = IOUtils.toString(getTestResourceInputStream("basicsPipeline-Jenkinsfile"), StandardCharsets.UTF_8);
String pipelineScript = getTestResourceAsUTF8String("basicsPipeline-Jenkinsfile");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preventing resource leaks by ensuring the stream is closed.

p.setDefinition(new CpsFlowDefinition(pipelineScript, true));
// copy resources into workspace
FilePath workspace = r.jenkins.getWorkspaceFor(p);
Expand All @@ -170,13 +170,20 @@ private InputStream getTestResourceInputStream(String fileName) {
return getClass().getResourceAsStream(getClass().getSimpleName() + "/" + fileName);
}

private String getTestResourceAsUTF8String(String resourceName) throws IOException {
try (InputStream is = getTestResourceInputStream(resourceName)) {
return IOUtils.toString(is, StandardCharsets.UTF_8);
}
}

private FilePath copyTestResourceIntoWorkspace(FilePath workspace, String fileName, int mask)
throws IOException, InterruptedException {
InputStream in = getTestResourceInputStream(fileName);
FilePath f = workspace.child(fileName);
f.copyFrom(in);
f.chmod(mask);
return f;
try (InputStream in = getTestResourceInputStream(fileName)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preventing resource leaks by ensuring the stream is closed.

FilePath f = workspace.child(fileName);
f.copyFrom(in);
f.chmod(mask);
return f;
}
}

}