title: update Jenkins credentials by script
body: <p>I have a Jenkins server running on Windows. It stores a username:password in the credentials plugin. This is a service user that gets its password updated regularly.</p>
  
  <p>I'm looking for a way to run a script, preferably Powershell, that will update that credential in the Jenkins password store so that it's always up to date when I use it in a build job script.</p>
  
  <p>The password is managed by a Thycotic Secret Server install so I should be able to automate the process of keeping this password up to date, but I have found almost no leads for how to accomplish this, even though the <a href="http://developer-blog.cloudbees.com/2015/04/the-credentials-api-in-jenkins.html" rel="noreferrer" title="blog post">blog post</a> by the guy who wrote the credentials api mentions almost exactly this scenario and then proceeds to just link to the credentials plugin's download page that says nothing about how to actually use the api. </p>
  
  <p><strong><em>Update</em></strong></p>
  
  <p>The accepted answer works perfectly, but the rest method call example is using curl, which if you're using windows doesn't help much. Especially if you are trying to invoke the REST URL but your Jenkins server is using AD Integration. To achieve this you can use the following script.</p>
  
  <p>Find the userId and API Token by going to People > User > configure > Show API Token.</p>
  
  <pre><code>$user = "UserID"
  $pass = "APIToken"
  $pair = "${user}:${pass}"
  
  $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
  $base64 = [System.Convert]::ToBase64String($bytes)
  
  $basicAuthValue = "Basic $base64"
  
  $headers = @{ Authorization = $basicAuthValue }
  
  
  
  Invoke-WebRequest `
      -uri "http://YourJenkinsServer:8080/scriptler/run/changeCredentialPassword.groovy?username=UrlEncodedTargetusername&amp;password=URLEncodedNewPassword" `
      -method Get `
      -Headers $headers
  </code></pre>