Created
May 12, 2023 14:13
-
-
Save AronllStone/d53fdb6dd0d03b67ec24e8abae9f1620 to your computer and use it in GitHub Desktop.
Example of the fileCredentials creation in Jenkins
This file contains hidden or 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.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