Created
May 3, 2016 20:49
-
-
Save jdennaho/92c66f7880a5ba9c39d090e6b5a52e37 to your computer and use it in GitHub Desktop.
Jenkins Credential Binding Plugin: creating a secret file programmatically
This file contains 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 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