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.
37 lines
1.3 KiB
37 lines
1.3 KiB
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 com.cloudbees.jenkins.plugins.sshcredentials.impl.*
|
|
import org.jenkinsci.plugins.plaincredentials.*
|
|
import org.jenkinsci.plugins.plaincredentials.impl.*
|
|
import hudson.util.Secret
|
|
import hudson.plugins.sshslaves.*
|
|
import org.apache.commons.fileupload.*
|
|
import org.apache.commons.fileupload.disk.*
|
|
import java.nio.file.Files
|
|
|
|
def env = System.getenv()
|
|
|
|
GITHUB_TOKEN = env['GITHUB_TOKEN']
|
|
|
|
domain = Domain.global()
|
|
store = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0].getStore()
|
|
|
|
println("== multibranch-github-pipeline.groovy => Starting.")
|
|
if ( GITHUB_TOKEN ) {
|
|
println("== multibranch-github-pipeline.groovy => Adding token.")
|
|
secretText = new StringCredentialsImpl(
|
|
CredentialsScope.GLOBAL,
|
|
"github-token",
|
|
"This is the token used for Github source branch plugin",
|
|
Secret.fromString(GITHUB_TOKEN)
|
|
)
|
|
|
|
store.addCredentials(domain, secretText)
|
|
println("== multibranch-github-pipeline.groovy => token added.")
|
|
|
|
}
|
|
|
|
println("== multibranch-github-pipeline.groovy => Done.")
|