So I want to have a file e.g. "whitelisted-files.txt" which contains the file-names jenkins are allowed to change. I´m trying to create a pre-receive hook that reads the latest version of "whitelisted-files.txt" from the branch that jenkins are pushing to. After reading I will compare the file-names to the files changed in the commit. To be clear, I don´t want to read the files being committed.
Is that possible? I guess there is no file-path where the file lies since it can exist in multiple branches and multiple versions in each branch? All help appreciated :)
I solved it myself:
ByteArrayOutputStream out = new ByteArrayOutputStream();
contentService.streamFile(repository, branch, pathToFile, (s) -> out);
try {
String content = out.toString(StandardCharsets.UTF_8.toString());
System.out.println("content: " + content);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Where contentService is initalized from the constructor and repository is from the RepositoryHookContext-class. https://docs.atlassian.com/DAC/javadoc/stash/3.11.3/api/reference/com/atlassian/stash/content/ContentService.html#streamFile%28com.atlassian.stash.repository.Repository,%20java.lang.String,%20java.lang.String,%20com.atlassian.stash.util.PageRequest,%20boolean,%20com.atlassian.stash.content.FileContentCallback%29
Hopefully the answer can be useful for someone :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.