Hi Kristian,

Thank you for your reply. It is good to know.
I worked around the problem with the following script that could also be 
useful for other:
installed = [] as Set

updateCenter.updateAllSites()

def install(id) {
  plugin = updateCenter.getPlugin(id)

  plugin.dependencies.each {
    install(it.key)
  }

  if (!pluginManager.getPlugin(id) && !installed.contains(id)) {
    println("installing plugin ${id}...")
    pluginManager.install([id], false).each { it.get() }
    installed.add(id)
  }
}

plugins.each {
  install(it)
}


Le mardi 25 avril 2017 02:52:15 UTC+2, Kristian Thornley a écrit :
>
> Hi Christophe
>
> I hope this is not too late and perhaps it might help others.  The Futures 
> job returned from the deploy operation contains isDone() operation you can 
> use like so by registering in a map and checking
>
> plugins.each {
> logger.info("> checking " + it)
> if (!pm.getPlugin(it)) {
> logger.info("> looking updatecenter for " + it)
> if (!initialized) {
> uc.updateAllSites()
> initialized = true
> }
> def plugin = uc.getPlugin(it)
> if (plugin) {
> logger.info("> installing " + it)
> *futures[it] = plugin.deploy()*
> installed = true;
> }
> }
> }
> *def allInstalled = false*
> * while(!allInstalled){*
> * def countOfDone = 0*
> * futures.each{ k, v -> *
> * if(v.isDone()){*
> * countOfDone++*
> * }*
> * }*
> * if(futures.size() == countOfDone){*
> * allInstalled = true;*
> * }else {*
> * logger.info <http://logger.info>("> count of done " + countOfDone)*
> * sleep(1000)*
> * }*
> * }*
> inputFile.write("initialized")
> logger.info("> plugins installed user created, initializing a restart!")
>
> On Wednesday, November 9, 2016 at 11:23:48 AM UTC+13, 
> [email protected] wrote:
>>
>> Hi,
>>
>> I use a small groovy script to install automatically a set of plugins 
>> (including their dependencies):
>> def pluginParameter="ldap matrix-auth ssh-credentials"
>> def plugins = pluginParameter.split()
>> def instance = Jenkins.getInstance()
>> def pluginManager = instance.getPluginManager()
>> def updateCenter = instance.getUpdateCenter()
>> def installed = false
>>
>> plugins.each {
>>   if (!pluginManager.getPlugin(it)) {
>>     def plugin = updateCenter.getPlugin(it)
>>     if (plugin) {
>>       println("Installing " + it)
>>       def installationJob = plugin.deploy()
>>       installed = true
>>     }
>>   }
>> }
>>
>> instance.save()
>> if (installed)
>>   instance.doSafeRestart()
>>
>> I want to wait that plugins are effectively installed before proceeding 
>> with next instruction of the script. Plugin installation is an async task. 
>> I tried to use plugin.deploy.get() as deploy() returns a Future but the 
>> script ends before all plugins and dependencies are effectively installed. 
>> Is there a way to wait until plugins and dependencies are effectively 
>> installed?
>>
>> Regards,
>> Christophe
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/bfc93796-b16b-48c6-9f31-4e0c9941b995%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to