Created
October 25, 2018 20:07
-
-
Save indyaah/38fd199e1bf90d8e93e319e6193cef47 to your computer and use it in GitHub Desktop.
Jenkins Create Secret Text Crendential programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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