Rudziankoŭ
Rudziankoŭ

Reputation: 11251

Format string without use of static methods

I use jenkins and I cannot use String.format or sprintf due to org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods sprintf java.lang.Object

I have settings file with creds:

    <username>%s</username>
    <password>%s</password>

I would like to format it anyway sprintf(MAVEN_SETTINGS, USERNAME, PASSWORD). How can I bypass it?

Upvotes: 0

Views: 1140

Answers (2)

Vojta Bar&#225;nek
Vojta Bar&#225;nek

Reputation: 61

I had the same issue with using sprintf(str, args...), but when I tried using String.format(str, args...) it worked. Maybe the policy changed over time? I am using Jenkins ver. 2.190.2 and there are no approved exceptions in the script-approval settings page.

Upvotes: 1

daggett
daggett

Reputation: 28624

what about non-static Formatter.format

new java.util.Formatter().format("n=%s, p=%s","name", "pass").toString()

Upvotes: 0

Related Questions