Hi there,
I'd like to implement a groovy script which checks out the contents of a single file from the SCM(be it Git,SVN...). I took a look into the insides of the Branch Source plugin to see how it gets only the Jenkinsfile, but still haven't gotten anything from it. I've also seen that, in the SCM API plugin the abstract class SCMFileSystem is able to retrieve a SCMFile, from which you can retrieve the contents. So I began writing a script to try and checkout something from GitHub with classes from the GitHub branch source implementation:
import jenkins.plugins.git.AbstractGitSCMSource;
import jenkins.plugins.git.AbstractGitSCMSource.SCMRevisionImpl;
import org.jenkinsci.plugins.github_branch_source.BranchSCMHead;
def revision = new AbstractGitSCMSource.SCMRevisionImpl(new BranchSCMHead("master"),"861fd864153dff3bd5e761b42be5ad63cc4a95a1");
Unfortunately an exception is thrown saying that "Scripts are not permitted to use new":
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new
org.jenkinsci.plugins.github_branch_source.BranchSCMHead java.lang.String
...
And I see that "new String()" may be blacklisted just like in this
issue. I'd like to know if checking a single file from SCM is possible and if this is the right approach.
Any help would be appreciated. Thank you for your attention!