Not able to url encode password parameter for credentialed git tagging

1,693 views
Skip to first unread message

Daniel Collette

unread,
Oct 27, 2016, 9:57:38 AM10/27/16
to Jenkins Users
Using multibranch pipeline plugin and credentials binding plugin and using this method to git tag, it is failing due to a character that requires url encoding in the password. 
To push to a git repo, it's required to URL encode (for example @'s in the username and password for "http://username:password@<gitrepo>" are not read properly)

When i import java.net.URLEncoder and URLEncoder.encode(password) in the groovy file i get this:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod java.net.URLEncoder encode java.lang.String

So, the question is, is there a way to URL encode the password that is idiomatic for Jenkinsfiles?

I would like to avoid something dirty like piping the parameter into bash and sed-ing the password to replace special characters if there is a cleaner and more readable solution.

Mark Waite

unread,
Oct 27, 2016, 10:24:17 AM10/27/16
to Jenkins Users
The simplest solution is to approve that method for use in your Jenkins.  Then you can use the URLEncoder class in Jenkinsfile on that instance.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b3b97111-84d4-4a4b-82fa-2f2d6eb97750%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Collette

unread,
Oct 27, 2016, 10:55:24 AM10/27/16
to Jenkins Users
Wow that was really simple. I never noticed that before. 

For anyone as ignorant as me:
in Jenkins web ui
Manage Jenkins >
In-process Script Approval >
Approve the signature

It worked great. 
The only issue is that now, instead of the credentials displaying as ***, it is url encoded in plain text in the logs. 

Thanks for the quick reply and simple solution. 
Reply all
Reply to author
Forward
0 new messages