You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
// This script is based on the source bellow:
|
|
// https://gist.github.com/ivan-pinatti/830ec918781060df03b12efd4a14096e
|
|
import com.cloudbees.plugins.credentials.*
|
|
import com.cloudbees.plugins.credentials.common.*
|
|
import com.cloudbees.plugins.credentials.domains.Domain
|
|
import com.cloudbees.plugins.credentials.impl.*
|
|
import jenkins.model.Jenkins
|
|
import org.jenkinsci.plugins.plaincredentials.impl.*
|
|
|
|
def dockerhubUser = new File("/run/secrets/jenkins_dockerhub_username").text.trim()
|
|
def dockerhubPassword = new File("/run/secrets/jenkins_dockerhub_password").text.trim()
|
|
|
|
def jenkinsKeyUsernameWithPasswordParameters = [
|
|
description: 'Apella docker-hub',
|
|
id : 'docker-hub-apella',
|
|
password : dockerhubPassword,
|
|
userName : dockerhubUser
|
|
]
|
|
|
|
// Gets Jenkins instance
|
|
Jenkins jenkins = Jenkins.getInstance()
|
|
|
|
// Gets credentials domain
|
|
def globalDomain = Domain.global()
|
|
|
|
// Gets credentials store
|
|
def credentialsStore = jenkins.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
|
|
|
|
// Defines username and password credentials
|
|
def jenkinsKeyUsernameWithPassword = new UsernamePasswordCredentialsImpl(
|
|
CredentialsScope.GLOBAL,
|
|
jenkinsKeyUsernameWithPasswordParameters.id,
|
|
jenkinsKeyUsernameWithPasswordParameters.description,
|
|
jenkinsKeyUsernameWithPasswordParameters.userName,
|
|
jenkinsKeyUsernameWithPasswordParameters.secret
|
|
)
|
|
|
|
// Adds credential to store
|
|
credentialsStore.addCredentials(globalDomain, jenkinsKeyUsernameWithPassword)
|
|
|
|
// Saves to disk
|
|
jenkins.save()
|