OpenSource
OpenSource

Reputation: 2257

Use jenkins subversion credential in my groovy script

As part of the build process, I need to check in a file after changing it. I can do it with a groovy script but I have to put the username password in the script. I want to try to avoid it if it's possible. Is there a way to use the credential already stored in Jenkins Source Code Management section in my groovy script?

Upvotes: 2

Views: 3069

Answers (2)

mooreds
mooreds

Reputation: 4978

This plugin should work.

https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin

It lets you pull credentials from jenkins and expose them as environment variables.

From there you can access them in your groovy script:

def env = System.getenv()

Upvotes: 1

CIGuy
CIGuy

Reputation: 5114

There is no way to do this that I know of, but you can accomplish essentially the same thing using a batch or shell script with the SVN command line client.

You will have to preform a checkout or commit once by hand on all your slaves, but once you do this the credentials will be cached on that machine and you can use them in your jobs via batch or shell commands without a user or password.

This isn't ideal, but it does get the job done.

Upvotes: 1

Related Questions