Well, now I don't know why my script isn't working. I had to modify it to 
remove the version numbers, just to get the thing to work. The blog, 
https://qiita.com/aespinosa/items/5d791310f0cb436eb71f works if I copy and 
paste their example,

import jenkins.model.Jenkins;

pm = Jenkins.instance.pluginManager

uc = Jenkins.instance.updateCenter
pm.plugins.each { plugin ->
plugin.disable()
}

deployed = false
def activatePlugin(plugin) {
if (! plugin.isEnabled()) {
  plugin.enable()
  deployed = true
}

plugin.getDependencies().each {
  activatePlugin(pm.getPlugin(it.shortName))
}
}

["git", "workflow-aggregator", "github-oauth", "job-dsl", 
"extended-read-permission"].each {
if (! pm.getPlugin(it)) {
  deployment = uc.getPlugin(it).deploy(true)
  deployment.get()
}
activatePlugin(pm.getPlugin(it))
}

if (deployed) {
Jenkins.instance.restart()
}


but as soon as I add my own Array, I get a nullpointerexception saying that 
it can't call deploy() with null objects.

import jenkins.model.Jenkins;

pm = Jenkins.instance.pluginManager

uc = Jenkins.instance.updateCenter
pm.plugins.each { plugin ->
  plugin.disable()
}

deployed = false
/**
 *
 */
def activatePlugin(plugin) {
  if (! plugin.isEnabled()) {
    plugin.enable()
      deployed = true
  }

  plugin.getDependencies().each {
    activatePlugin(pm.getPlugin(it.shortName))
  }
}

/** this works.
[
  "git", 
  "workflow-aggregator", 
  "github-oauth", 
  "job-dsl", 
  "extended-read-permission"
].each {
  if (! pm.getPlugin(it)) {
    deployment = uc.getPlugin(it).deploy(true)
      deployment.get()
  }
  activatePlugin(pm.getPlugin(it))
}
*/

[
  "ant",
  "build-timeout",
  "credentials",
  "email-ext",
  "github-branch-source:",
  "gradle",
  "jobConfigHistory",
  "ldap",
  "matrix-auth",
  "antisamy-markup-formatter",
  "pam-auth",
  "pipeline",
  "pipeline-github-lib",
  "ssh-slaves",
  "subversion",
  "timestamper",
  "ws-cleanup"
].each {
  if (! pm.getPlugin(it)) {
    deployment = uc.getPlugin(it).deploy(true)
      deployment.get()
  }
  activatePlugin(pm.getPlugin(it))
}

Currently, it makes no sense. To me those are structured the same, but the 
second array doesn't work. 

On Tuesday, December 18, 2018 at 3:21:52 PM UTC-6, Phillip Dudley wrote:
>
> What I ended up doing is using what I had previously to setup Jenkins, 
> login, and install the Job Configuration History plugin, and got the output 
> of the config.xml. For whatever reason, doing the 
> http://JENKINSURL:8080/job/NAME/config.xml would just result in a blank 
> page, and not actually show the configuration of the GitHub Source Branch 
> job. 
>
> However, I noticed that the config is tied very specifically to specific 
> versions of Plugins. I can install plugins, but if those change, then they 
> break my job.
>
> /**
>  * activatePlugin activates given plugins.
>  * The plugin parameter is a pluginManager object(?)
>  * 
>  * @param plugin [Object]
>  * 
>  * @return nil 
>  */
> def activatePlugin(plugin) {
>   // If our specified plugin isn't enabled, enable it.
>   if (! plugin.isEnabled()) {
>     plugin.enable()
>     // Set our state to true.
>     deployed = true
>   }
>   // Go through each dependency of our plugins, and enable those.
>   // Otherwise our plugins wouldn't work even if they're installed.
>   plugin.getDependencies().each {
>     activatePlugin(pluginManager.getPlugin(it.shortName))
>   }
> }
>
> // As of 2018-12-18
> def plugin_list = [
>   "ant:1.9",
>   "build-timeout:1.19",
>   "email-ext:2.63",
>   "github-branch-source:2.4.1",
>   "gradle:1.29",
>   "ldap:1.20",
>   "matrix-auth:2.3",
>   "antisamy-markup-formatter:1.5",
>   "pam-auth:1.4",
>   "pipeline:2.6",
>   "pipeline-github-lib:1.0",
>   "ssh-slaves:1.29.1",
>   "subversion:2.12.1",
>   "timestamper:1.8.10",
>   "ws-cleanup:0.37",
> ]
>
> // Loop through all of the plugins and install/update and activate them.
> plugin_list.each { plugin ->
>   // If the plugin isn't being installed, update it.
>   if (! pluginManager.getPlugin(plugin)) {
>     deployment = updateCenter.getPlugin(plugin).deploy(true)
>     deployment.get()
>   }
>   // Activate the plugin and all of its dependencies.
>   activatePlugin(pluginManager.getPlugin(plugin))
> }
>
> However, there is an overloaded method in the updateCenter called 
> getPlugin(String name, and VersionNumber version)
>
>
>    - 
>    
> https://javadoc.jenkins.io/hudson/model/UpdateCenter.html#getPlugin-java.lang.String-hudson.util.VersionNumber-
>
> I'm not sure where to find the VersionNumber or how to get that to give to 
> this method. 
>
> On Friday, December 14, 2018 at 3:46:05 PM UTC-6, Phillip Dudley wrote:
>>
>> Would anyone have any pointers to configuring the GitHub Organization 
>> Item/Job with Groovy so that when my Jenkins instance starts up, it reads 
>> the 
>>
>> $JENKINS_HOME/init.groovy.d/
>>
>> folder and configures a default job to perform GitHub Organization 
>> scanning for Jenkinsfiles? 
>>
>> I've got most of the other stuff I need such as setting banners, 
>> installing plugins, configuring default Jenkins users and assigning them 
>> permissions via the matrix-auth plugin. Even finally hooked up to LDAP and 
>> I can authenticate. However, I don't seem to find too much on configuring 
>> that plugin except through the UI. Most of my Googling returns results for 
>> using Jenkinsfiles, or Groovy tutorials, but not actually setting up and 
>> configuring that plugin. 
>>
>> TL;DR,
>> Looking for a direction to learn how to configure the GitHub Organization 
>> job to scan my GitHub Organization for Jenkinsfiles and start performing 
>> Jobs. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/1b08aba7-53c7-442f-972c-40c36c5d5392%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to