Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding plugin specific code before CasC installs plugin kills Jenkins #625

Closed
Nicabus opened this issue Oct 30, 2018 · 7 comments
Closed

Comments

@Nicabus
Copy link

Nicabus commented Oct 30, 2018

New Jenkins server. CasC plugin is installed, then Jenkins is restarted and config file added. Having the code for the bitbucket server endpoint in the CasC config file causes Jenkins to not boot and only show the below stack trace.

When system is created without bitbucket entry in config, and only added after CasC installs all the plugins and Jenkins manually restarted again with the new config info in the yaml, it works.

This kinda defeats the purpose of having configuration code if having the desired config loaded at the same time/prior to the plugin install causes the system to crash. Is there a way to make CasC ignore code that isn't applicable until after a plugin is installed?

Am I doing something wrong with how i'm setting up the yaml or my order of operations? None of the plugins I install seem to auto restart Jenkins as in #622.

Any help would be appreciated.

  • [2.138.2] Jenkins version
  • [1.2] CasC Plugin version
  • [CentOS Linux release 7.5.1804 (Core)] OS

jenkins.yaml:

plugins:
  required:
    blueocean: latest
    greenballs: latest
    active-directory: latest
    nunit: latest
    job-dsl: latest
  sites:
  - id: "default"
    url: "https://updates.jenkins.io/update-center.json"
jenkins:
  agentProtocols:
  - "JNLP4-connect"
  - "Ping"
  crumbIssuer:
    standard:
      excludeClientIPFromCrumb: false
  disableRememberMe: false
  mode: NORMAL
  numExecutors: 0
  primaryView:
    all:
      name: "all"
  quietPeriod: 5
  scmCheckoutRetryCount: 0
  slaveAgentPort: 9999
  systemMessage: "This Jenkins server has been auto configured"
  views:
  - all:
      name: "all"
unclassified:
  bitbucketendpointconfiguration:
    endpoints:
    - bitbucketServerEndpoint:
        displayName: "Stash"
        manageHooks: false
        serverUrl: "http://<IP Removed>"

Stack trace:

io.jenkins.plugins.casc.ConfiguratorException: Invalid configuration elements for type class jenkins.model.GlobalConfigurationCategory$Unclassified : bitbucketendpointconfiguration.
Available attributes : administrativemonitorsconfiguration, artifactManager, cascglobalconfig, cloud, defaultView, location, masterBuild, myView, nodeProperties, plugin, pollSCM, projectNamingStrategy, quietPeriod, scmRetryCount, shell, usagestatistics, viewsTabBar
	at io.jenkins.plugins.casc.BaseConfigurator.handleUnknown(BaseConfigurator.java:363)
	at io.jenkins.plugins.casc.BaseConfigurator.configure(BaseConfigurator.java:352)
	at io.jenkins.plugins.casc.BaseConfigurator.check(BaseConfigurator.java:273)
	at io.jenkins.plugins.casc.ConfigurationAsCode.lambda$checkWith$8(ConfigurationAsCode.java:645)
	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:608)
Caused: io.jenkins.plugins.casc.ConfiguratorException: unclassified: error configuring 'unclassified' with class io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator configurator
	at io.jenkins.plugins.casc.ConfigurationAsCode.invokeWith(ConfigurationAsCode.java:614)
	at io.jenkins.plugins.casc.ConfigurationAsCode.checkWith(ConfigurationAsCode.java:645)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:630)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:542)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:272)
	at io.jenkins.plugins.casc.ConfigurationAsCode.init(ConfigurationAsCode.java:264)
Caused: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
Caused: java.lang.Error
	at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:110)
	at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1069)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused: org.jvnet.hudson.reactor.ReactorException
	at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:282)
	at jenkins.InitReactorRunner.run(InitReactorRunner.java:48)
	at jenkins.model.Jenkins.executeReactor(Jenkins.java:1103)
	at jenkins.model.Jenkins.<init>(Jenkins.java:907)
	at hudson.model.Hudson.<init>(Hudson.java:85)
	at hudson.model.Hudson.<init>(Hudson.java:81)
	at hudson.WebAppMain$3.run(WebAppMain.java:233)
Caused: hudson.util.HudsonFailedToLoad
	at hudson.WebAppMain$3.run(WebAppMain.java:250)
@guice
Copy link

guice commented Jan 15, 2019

Same issue, this one with docker-plugin:

  • [ver. 2.150.1 ] Jenkins version
  • [1.4 ] Plugin version
  • [ jenkins/jenkins:lts] OS

Fresh jenkins/jenkins docker image; install CASC plugins. Create new configuration file:

plugins:
  required:
    docker-plugin: latest
  sites:
    - id: "default"
      url: "https://updates.jenkins.io/experimental/update-center.json"
jenkins:
  clouds:
    - docker:
        name: "docker"
        dockerApi:
          dockerHost:
            uri: "unix:///var/data/sys/run/docker/docker.sock"

Attempt to reload configuration:

java.lang.IllegalArgumentException: No hudson.slaves.Cloud implementation found for docker
	at io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator.findDescribableBySymbol(HeteroDescribableConfigurator.java:148)

The bug is simple: CASC is not restarting the Jenkins instance when installing required plugins, resulting in an error in configurations because hudson.slaves.Cloud is not found because docker-plugin was never enabled via restart.

@jetersen
Copy link
Member

This is #280 once again.
Please preinstall plugins: see https://github.com/jenkinsci/docker#preinstalling-plugins

@guice
Copy link

guice commented Jan 15, 2019

@Casz Is this the only way? How do we managed CASC for new plugins?

I'm trying to configure a third-party install of Jenkins. It doesn't come with these plugins pre-installed; I need to add them. I also want to SCM the need of these plugins and their configurations. We're running into a chicken 'n egg situation here.

How do I pre-install plugins, via Code, on a third-party pre-installed Jenkins instance?

@jetersen
Copy link
Member

jetersen commented Jan 16, 2019

Roll your jenkins instance into a docker container (most of that is already done for you https://hub.docker.com/r/jenkins/jenkins/ ), during the docker build you preinstall the plugins. Then deploy the container with the new plugins.

Or use https://github.com/jenkinsci/custom-war-packager

Here is are some example repos:
https://github.com/Praqma/praqma-jenkins-casc
https://github.com/oleg-nenashev/demo-jenkins-config-as-code
https://github.com/oleg-nenashev/jenkins-custom-war-packager-ci-demo

here is our take on a dockerfile for our jenkins master

FROM jenkins/jenkins:lts-alpine

ARG threeshapecrt=/usr/local/share/ca-certificates/3shape.crt
ARG keystore=$JAVA_HOME/jre/lib/security/cacerts
ARG rootca=https://artifactorydk.3shape.local/Download/tools/3shape-root-ca.pem
ENV CASC_JENKINS_CONFIG=/usr/share/jenkins/ref/jenkins.yaml

# add ca cert
USER root
RUN curl -sSfLk $rootca -o $threeshapecrt && \
    keytool -file $threeshapecrt -trustcacerts -import -alias 3shape-ca -storepass changeit -noprompt -keystore $keystore
RUN update-ca-certificates

# disable upgrade wizard
USER jenkins
RUN echo $JENKINS_VERSION | tee \
    /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state \
    /usr/share/jenkins/ref/jenkins.install.InstallUtil.lastExecVersion

# copy preinstalled plugins list
COPY --chown=jenkins plugins.txt /usr/share/jenkins/ref/plugins.txt

# plugin installation layer
RUN mkdir -p /usr/share/jenkins/ref/plugins && \
    install-plugins.sh < /usr/share/jenkins/ref/plugins.txt && \
    curl -sSfL https://artifactorydk.3shape.local/maven/argelbargel/jenkins/plugins/gitlab-branch-source/0.7.6.2-SNAPSHOT/gitlab-branch-source-0.7.6.2-20181203.211221-1.hpi \
    -o /usr/share/jenkins/ref/plugins/gitlab-branch-source.jpi && \
    curl -sSfL https://artifactorydk.3shape.local/artifactory/maven/org/jenkins-ci/plugins/docker-workflow/1.18.0.2-SNAPSHOT/docker-workflow-1.18.0.2-20181213.095203-1.hpi \
    -o /usr/share/jenkins/ref/plugins/docker-workflow.jpi && \
    curl -sSfL http://repo.jenkins-ci.org/incrementals/org/jenkins-ci/plugins/git-client/3.0.0-beta6-rc1827.ac5f9c819272/git-client-3.0.0-beta6-rc1827.ac5f9c819272.hpi  \
    -o /usr/share/jenkins/ref/plugins/git-client.jpi && \
    curl -sSfL https://artifactorydk.3shape.local/artifactory/maven/org/jenkins-ci/plugins/vsphere-cloud/3.0-SNAPSHOT/vsphere-cloud-3.0-20181212.233446-3.hpi \
    -o /usr/share/jenkins/ref/plugins/vsphere-cloud.jpi

# copy configuration as code config
COPY --chown=jenkins jenkins.yaml /usr/share/jenkins/ref/jenkins.yaml

@ewelinawilkosz
Copy link
Contributor

running a jenkins in a docker container and installing plugins via install-plugins.sh is the recommended solution. It comes with limitations but it is the only one that works good right now

@guice
Copy link

guice commented Jan 22, 2019

That's unfortunate, then.

I don't have control over the container. It's a third-party container (Altoros Jenkins) installed by a third-party (Pivotal). I'll just re-run the configuration multiple times until everything installs and restarts.

This is nice and all if you have direct control over your Jenkins installs. However, a number of us don't.

@jetersen
Copy link
Member

We no longer support plugin installation as of v1.8
see #769 and [JENKINS-53767] Offer plugin management tooling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants