Issue
-
There can be situations where you will need to change periodically the password for a credential used while authenticatin in manual mode in the Team Foundation Version Control section of a job. This will most likely happen when your security policies recommend these passwords to be rotated periodically.
-
Is it possible to script this change?
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise
-
CloudBees Jenkins Enterprise - Managed controller
Resolution
In order to satisfy the requirement of this use case there are two approaches:
-
Change the Team Foundation Version Control type to GIT, as explained in this article. Once that you choose a Git version control type repository, you will be able to use Jenkins credentials, hence you will have scripted ways to do this such as this script.
-
The other option would be to use the script below to change the credentials for a given job. It would be relatively easy to tweak this script to affect a list of jobs or a set of jobs satisfying a condition:
def jobName="[your job name]" // getting the job Object def myJob= Jenkins.instance.getItemByFullName(jobName) //Accessing the SCM object for the job def scm = myJob.getScm() //If the job is configured to use this specific Credential Configurer class if(scm!=null && (scm.getCredentialsConfigurer() instanceof hudson.plugins.tfs.model.ManualCredentialsConfigurer)){ //Resetting the password to the Manual Credentials configurer scm.password= new hudson.util.Secret("[new pass]") myJob.save() println "You have set the password of "+ jobName + " to :"+scm.password }