Last active
November 13, 2018 17:29
-
-
Save gwsu2008/6a63f7d5e83db3adb5cc1e0d5c103620 to your computer and use it in GitHub Desktop.
jenkins_store_credentials.groovy
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
secretText = new StringCredentialsImpl( | |
CredentialsScope.GLOBAL, | |
"secret-text", | |
"Secret Text Description", | |
Secret.fromString("some secret text goes here")) | |
file = new File("/path/to/some/file") | |
noFileItem = [ getName: { return "" } ] as FileItem | |
FileCredentailsImpl can take a file from a do | |
secretFile = new FileCredentialsImpl( | |
CredentialsScope.GLOBAL, | |
"secret-file", | |
"Secret File Description" | |
noFileItem, // Don't use FileItem | |
file.getName(), | |
file.text) | |
store.addCredentials(domain, secretText) | |
store.addCredentials(domain, secretFile) | |
import com.cloudbees.plugins.credentials.*; | |
import com.cloudbees.plugins.credentials.domains.Domain; | |
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl; | |
def secret = '''Hi | |
there, | |
only | |
test''' | |
def secretBytes = SecretBytes.fromBytes(secret.getBytes()) | |
def credentials = new FileCredentialsImpl(CredentialsScope.GLOBAL, 'my test file', 'description', 'file.txt', secretBytes) | |
SystemCredentialsProvider.instance.store.addCredentials(Domain.global(), credentials) | |
import com.cloudbees.plugins.credentials.*; | |
import com.cloudbees.plugins.credentials.domains.Domain; | |
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl; | |
import java.nio.file.*; | |
Path fileLocation = Paths.get("/path/to/some/file.txt"); | |
def secretBytes = SecretBytes.fromBytes(Files.readAllBytes(fileLocation)) | |
def credentials = new FileCredentialsImpl(CredentialsScope.GLOBAL, 'my test file', 'description', 'file.txt', secretBytes) | |
SystemCredentialsProvider.instance.store.addCredentials(Domain.global(), credentials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment