configuration-as-code-plugin icon indicating copy to clipboard operation
configuration-as-code-plugin copied to clipboard

[Feature] Plugin installation

Open ewelinawilkosz opened this issue 9 years ago • 12 comments

If we install new plugins in the plugin.yml file, how can they be updated without restart as many plugins require restart on update.

ewelinawilkosz avatar Nov 24 '17 07:11 ewelinawilkosz

I don't expect configuration-as-code to fix all jenkins design issues :-P configuration-as-code could easily check a required list of plugin is installed, as some sort of a company policy check. But installing plugins is a distinct job, which require a restart in most cases, and also hardly can be managed by this plugin from inside jenkins, would need to run priori to it's execution. Better imho to rely on plugins.txt as in docker image.

ndeloof avatar Nov 27 '17 19:11 ndeloof

My current thoughts on this feature:

We could implement a dedicated Configurator for a new plugins RootElement and related new management component.

  • relies on a map of plugin ID -> version
plugins:
  git: 2.4
  maven: 1.2
  • checks PluginManager for installed plugins and compare with required version.
  • react on version mismatch or plugin failure by replacing stapler app with an error page to block startup (or System.exit ?).

If we want to offer an equivalent for docker image's install-plugins.sh script we will need one additional step :

  • react on missing plugins by triggering installation and restart jenkins.

But this would have to run after jenkins.updateCenter.sites and jenkins.proxy, have been configured, and also the yaml configuration would probably be invalid at parsing time as referenced plugins aren't installed yet (chicken and egg issue).

So we will need to have a special configuration file loaded before all others, to set jenkins.updateCenter.sites, jenkins.proxy, and required plugins, then (maybe after restart) parse other configuration files. As jenkins.proxy is configured on UI via PluginManager, I suggest we define a special role for a plugins.yaml file to be loaded first and used to configure PluginManager (and only this guy) :

plugins: # alias for PluginManager
  updateSites:
    - "http://jenkins-uc.acme.com"
  proxy:
    name: "proxy.acme.com"
    port: 8080
    userName: foo
    password: ${INJECT}
  required:
    git: 2.4
    maven: 1.2

ndeloof avatar Jan 10 '18 15:01 ndeloof

Right after we implemented the change that puts all other elements under a fake 'jenkins' root element, should this also be put as a child of this fake root element? So we have:

jenkins: 
   plugins: ...
   mailer: ...

MadsNielsen avatar Jan 29 '18 08:01 MadsNielsen

I wouldn't say so - we're putting some elements under 'jenkins' so it mimics UI - we configure Mailer under 'Configure System' in Jenkins and that's the 'jenkins' root element Plugins have separate subpage, 'Manage Plugins' so in my opinion 'plugins' deserves to be root element itself - if that's possible

ewelinawilkosz avatar Jan 29 '18 11:01 ewelinawilkosz

@ewelinawilkosz Super just what i thought! :)

I've started to do a bit of work on this...and i've got something working atleast (I can set proxy on the jenkins instance)...but im not sure im doing it the right way. I can correctly configure a proxy configuration

    @Override
    public PluginManager configure(Object config) throws Exception {
        Map map = (Map) config;
        Configurator<ProxyConfiguration> pc = Configurator.lookup(ProxyConfiguration.class);
        ProxyConfiguration pcc = pc.configure(map.get("proxy"));
        Field f = Jenkins.class.getDeclaredField("proxy");
        f.set(Jenkins.getInstance(), pcc);
        Jenkins.getInstance().save();
        return null;
    }

I'm a bit unsure here, first of all i started out with a root configurator named plugins...and an attribute proxy added in the describe method of type ProxyConfiguration. It's databound so the configure method correcty returns an object we can play with.

What would be the best root element to start with? @ndeloof suggested PluginManager, but some of the stuff i need to set seems to belong to UpdateCenter (I.e sites).

MadsNielsen avatar Jan 29 '18 11:01 MadsNielsen

I don't think we have any adequate class in jenkins model for this purpose : update sites for sample have no associated UI for configuration. So probably better to define a set of custom data classes that you'll then use to configure plugin manager and other related elements (proxy, etc)

see for sample https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/src/main/java/org/jenkinsci/plugins/casc/core/HudsonPrivateSecurityRealmConfigurator.java#L35

ndeloof avatar Jan 29 '18 12:01 ndeloof

By the way, about

Field f = Jenkins.class.getDeclaredField("proxy");
f.set(Jenkins.getInstance(), pcc);

proxy being public, you can just write Jenkins.getInstance.proxy = pcc

ndeloof avatar Jan 29 '18 12:01 ndeloof

@ndeloof Thanks for the input! I'll try that approach instead.

MadsNielsen avatar Jan 29 '18 12:01 MadsNielsen

issue discussed at post-FOSDEM hackathon (https://docs.google.com/document/d/1IlVC9wqYsaa3aO2krYTu6P8olX6K5jZxG4zQwbKXRyc/edit9) with following conclusion:

  • Implement “Light solver” based plugin installation scheme in CaC
  • Introduce metadata in the update center to make the light solver better than the dumb algorithm

@ndeloof will land his existing code into the repository

User experience: What we’d like to do

  • B: just list “git” and “blueocean” and maybe specify their versions, have the dependencies figured out automatically
  • KK: provide immutability. Be able to bring bacak the same exact plugin versions a year later

Proposed scenario:

$ cat > Pluginsfile
plugin “git”, “2.3”
plugin “blueocean”, “1.3”

$ cac Pluginfile
(this resolves dependencies, etc, then creates Pluginfile.lock that lists exact versions)
$ git add Pluginfile.lock
(you commit this result to ensure immutability)

# Updating dependencies
$ cac -preferMinimalModification | -preferLatest Pluginfile
(this will update Pluginfile.lock with new dependencies)
$ git commit Pluginfile.lock

see issue #6 above for how to reload this new setting into Jenkins

Also that means we detach plugins from jenkins.yaml and put it in separate file

ewelinawilkosz avatar Feb 05 '18 12:02 ewelinawilkosz

@ndeloof are you going to work on that one?

ewelinawilkosz avatar Mar 04 '18 13:03 ewelinawilkosz

Yes, I'll work on a proposal next week

ndeloof avatar Mar 04 '18 17:03 ndeloof

let's continue in #104

ewelinawilkosz avatar Mar 12 '18 13:03 ewelinawilkosz