Skip to content

Instantly share code, notes, and snippets.

@AronllStone
Created May 12, 2023 14:13
Show Gist options
  • Save AronllStone/d53fdb6dd0d03b67ec24e8abae9f1620 to your computer and use it in GitHub Desktop.
Save AronllStone/d53fdb6dd0d03b67ec24e8abae9f1620 to your computer and use it in GitHub Desktop.
Example of the fileCredentials creation in Jenkins
import jenkins.model.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey
import org.jenkinsci.plugins.plaincredentials.StringCredentials
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl
instance = Jenkins.instance
domain = Domain.global()
store = instance.getExtensionList("com.cloudbees.plugins.credentials.SystemCredentialsProvider")[0].getStore()
file_content = '''
<paste your file ontent here>
'''
bytes = SecretBytes.fromBytes(file_content.getBytes())
file_secret = new FileCredentialsImpl(CredentialsScope.GLOBAL, "<secret id>", "", "<secret file name>", bytes)
store.addCredentials(domain, file_secret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment