Skip to content

Instantly share code, notes, and snippets.

@marcelaraujo
Last active March 20, 2020 00:24
Show Gist options
  • Select an option

  • Save marcelaraujo/1480f83532ecd54d46ea1f69c3ce5ef9 to your computer and use it in GitHub Desktop.

Select an option

Save marcelaraujo/1480f83532ecd54d46ea1f69c3ce5ef9 to your computer and use it in GitHub Desktop.
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