Skip to content

Instantly share code, notes, and snippets.

@jdennaho
Created May 3, 2016 20:49
Show Gist options
  • Save jdennaho/92c66f7880a5ba9c39d090e6b5a52e37 to your computer and use it in GitHub Desktop.
Save jdennaho/92c66f7880a5ba9c39d090e6b5a52e37 to your computer and use it in GitHub Desktop.
Jenkins Credential Binding Plugin: creating a secret file programmatically
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import org.jenkinsci.plugins.plaincredentials.*
import org.jenkinsci.plugins.plaincredentials.impl.*
import org.apache.commons.fileupload.FileItem
//Replace file-id, file-description, filepath and filename with appropriate values for your file
final File file = new File('filepath/filename')
fileItem = [ getName: { return "filename" }, get: { return file.getBytes() } ] as FileItem
secretFile = new FileCredentialsImpl(
CredentialsScope.GLOBAL,
"file-id",
"file-description",
fileItem, // Don't use FileItem
null,
null)
store.addCredentials(domain, secretFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment