Skip to content

Instantly share code, notes, and snippets.

@indyaah
Created October 25, 2018 20:07
Show Gist options
  • Save indyaah/38fd199e1bf90d8e93e319e6193cef47 to your computer and use it in GitHub Desktop.
Save indyaah/38fd199e1bf90d8e93e319e6193cef47 to your computer and use it in GitHub Desktop.
Jenkins Create Secret Text Crendential programmatically
import jenkins.model.*
import hudson.util.Secret
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl
import org.jenkinsci.plugins.plaincredentials.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
println("Setting credentials")
def domain = Domain.global()
def store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
def secret = Secret.fromString("your password")
def user = new StringCredentialsImpl(CredentialsScope.GLOBAL, 'PROGRAMMATIC_CREDS', 'PROGRAMMATIC_CREDS', secret)
store.addCredentials(domain, user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment