Created
May 30, 2018 11:36
-
-
Save msheiny/7bb219c1cbfa963bc265814559543ae4 to your computer and use it in GitHub Desktop.
jenkins groovy init script for injecting google compute creds into credential store
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 org.apache.commons.fileupload.FileItem | |
import com.cloudbees.plugins.credentials.domains.* | |
import com.google.jenkins.plugins.credentials.oauth.JsonServiceAccountConfig | |
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials | |
import java.io.FileInputStream | |
domain = Domain.global() | |
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore() | |
def filey = new FileInputStream('/tmp/google-creds-on-jenkins-master.json') | |
fileItem = [ getSize: { return 1L }, getInputStream: { return filey } ] as FileItem | |
def ServiceAccount = new JsonServiceAccountConfig(fileItem, null) | |
def GoogleAccount = new GoogleRobotPrivateKeyCredentials("project-id", ServiceAccount, null) | |
store.addCredentials(domain, GoogleAccount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @msheiny,
Your code didn't work for me, so I did some improvements now it's working. (Jun/2019).
Anyway, thank you so much. Your code was the inspiration. ;-)