Jenkins supports Groovy scripts. You can get the script console by opening the URL /script your Jenkins instance in the browser. (i.e. http: // localhost: 8080 / script )
The advantage of Groovy (over the file system or something else) is that these Groovy scripts run in Jenkins and have access to everything (config, plugins, tasks, etc.).
Then the following code will change the password for the user "BillHurt" to "s3crEt!":
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl def changePassword = { username, new_password -> def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, Jenkins.instance ) def c = creds.findResult { it.username == username ? it : null } if ( c ) { println "found credential ${c.id} for username ${c.username}" def credentials_store = Jenkins.instance.getExtensionList( 'com.cloudbees.plugins.credentials.SystemCredentialsProvider' )[0].getStore() def result = credentials_store.updateCredentials( com.cloudbees.plugins.credentials.domains.Domain.global(), c, new UsernamePasswordCredentialsImpl(c.scope, c.id, c.description, c.username, new_password) ) if (result) { println "password changed for ${username}" } else { println "failed to change password for ${username}" } } else { println "could not find credential for ${username}" } } changePassword('BillHurt', 's3crEt!')
Classical Automation ( /scriptText )
To automate the execution of this script, you can save it in a file (let /tmp/changepassword.groovy ) and run the following curl command:
curl -d "script=$(cat /tmp/changepassword.groovy)" http://localhost:8080/scriptText
which should respond with HTTP 200 status HTTP 200 and text:
credentials found 801cf176-3455-4b6d-a461-457a288fd202 for username BillHurt
password changed for BillHurt
Automation with Scriptler Plugin
You can also install the Jenkins Scriptler plugin and proceed as follows:

- Open the Scriptler tool in the side menu

- fill in the 3rd first field, taking care to set the Id field to
changeCredentialPassword.groovy - check the Define script checkbox.
- add 2 parameters:
username and password - paste the following script:
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl def changePassword = { username, new_password -> def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, jenkins.model.Jenkins.instance ) def c = creds.findResult { it.username == username ? it : null } if ( c ) { println "found credential ${c.id} for username ${c.username}" def credentials_store = jenkins.model.Jenkins.instance.getExtensionList( 'com.cloudbees.plugins.credentials.SystemCredentialsProvider' )[0].getStore() def result = credentials_store.updateCredentials( com.cloudbees.plugins.credentials.domains.Domain.global(), c, new UsernamePasswordCredentialsImpl(c.scope, null, c.description, c.username, new_password) ) if (result) { println "password changed for ${username}" } else { println "failed to change password for ${username}" } } else { println "could not find credential for ${username}" } } changePassword("$username", "$password")
Now you can call the following URL to change the password (replacing the username and password ): http: // localhost: 8080 / scriptler / run / changeCredentialPassword.groovy? Username = BillHurt & password = s3crEt% 21 (note the need for urlencode values parameters)
or with curl:
curl -G http://localhost:8080/scriptler/run/changeCredentialPassword.groovy --data-urlencode 'username=BillHurt' --data-urlencode "password=s3crEt!"
Sources:
Search engine: use the keywords 'Jenkins.instance.' , 'com.cloudbees.plugins.credentials' and UsernamePasswordCredentialsImpl