Skip to content

Instantly share code, notes, and snippets.

@Buzer
Created April 30, 2019 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buzer/5148372464e2481a797091682fabbad5 to your computer and use it in GitHub Desktop.
Save Buzer/5148372464e2481a797091682fabbad5 to your computer and use it in GitHub Desktop.
Jenkins.instance.getInjector().getInstance(AdminWhitelistRule.class).setMasterKillSwitch(false)
def store = Jenkins.instance.getExtensionList("com.cloudbees.plugins.credentials.SystemCredentialsProvider")[0].getStore()
def ghspec = new ArrayList<DomainSpecification>()
ghspec.add(new HostnameSpecification("api.github.com", ""))
def ghdomain = new Domain("api.github.com", "GitHub", ghspec)
ghuserpasscreds = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
"ghuserpass", "GitHub username & password",
ghcreds.username,
ghcreds.password
)
ghtokencred = new StringCredentialsImpl(
CredentialsScope.GLOBAL,
"ghtoken",
"GitHub token",
Secret.fromString(ghcreds.token)
)
store.addCredentials(ghdomain, ghtokencred)
store.addCredentials(Domain.global(), ghuserpasscreds)
def jobName = "foobar"
def configXml = new File("/etc/jenkins/jobs/githuborgs/foobar.xml").text.trim()
def xmlStream = new ByteArrayInputStream(configXml.getBytes())
Jenkins.instance.createProjectFromXML(jobName, xmlStream)
Jenkins.instance.getJob(jobName).scheduleBuild(5, new hudson.model.Cause.RemoteCause("localhost", "Inital refresh"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment