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

Automatically reload configuration if change in jenkins.yaml detected #76

Closed
ewelinawilkosz opened this issue Feb 5, 2018 · 26 comments
Closed

Comments

@ewelinawilkosz
Copy link
Contributor

manual reload of configuration is npw supported in UI
we need also a functionality to reload automatically when change in the file is detected - on disk or in git repository

@jhoblitt
Copy link
Member

I would also appreciate an api endpoint or cli sub-command to trigger a reload. At present, I'm using CM (puppet) to restart the master when the config yaml changes but that is probably more heavy handed than needed.

@jhoblitt
Copy link
Member

Actually, it looks like this already exists from look at the helm chart which is running a command via ssh.

@conn
Copy link

conn commented Mar 27, 2019

This should be optionally disabled so that you can hold off until pipelines finish or any other important things are done.

@holmesb
Copy link
Contributor

holmesb commented Mar 27, 2019

This should be optionally disabled so that you can hold off until pipelines finish

The helm chart's "casc reload" sidecar outputs a boolean value that indicates whether reload was successful. If you deploy jenkins itself using a pipeline (we use a "seed" jenkins for this) that first deploys a "staging" jenkins, if reload fails, the pipeline can be halted prior to deploying changed config to a "production" jenkins. This removes the risk of attempting to load bad config on your main jenkins instance. I know this isn't directly relevant to your point, but reduces risk during reload.

@conn
Copy link

conn commented Mar 27, 2019

Not everyone is running Jenkins on Kubernetes. This needs to be available for Jenkins being ran from other types of environments. There are also always going to be some differences between staging and production configurations as well. Given that Jenkins is designed as a monolith without great high available options, you are forced to time your releases accordingly.

While I could just wait on changing the configuration until I'm ready, having more options is more useful than having less.

@jhoblitt
Copy link
Member

jhoblitt commented Mar 27, 2019

I suspect it wouldn't be very difficult to hack together a systemd service unit to run the same docker image as is used by the chart. Granted, that only works for people running the master on linux, but it is a simple solution that avoids duplicated effort.

@conn
Copy link

conn commented Mar 28, 2019

I'm sure it's possible to hack anything together, but it doesn't mean that it's good design.

I personally think automatic reload is useful, and I definitely will want it for some situations. However, the automatic reload should have the option to be disabled for situations where it would undesirable.

This is pretty simple and achievable in a way that folks that want either can be satisfied. I'm not sure why this idea is met with resistance in favor of more complicated or fancy ideas.

@timja
Copy link
Member

timja commented Mar 28, 2019

I think the simplest generic way of doing this would be:

A webhook endpoint is added for reloading, which has a query parameter for authenticating the request (to prevent DoS attacks)

@vladfr
Copy link

vladfr commented Jul 5, 2019

I've implemented this via a Jenkinsfile that does 2 curls: one to check the config, and one to reload. An improvement we added is, instead of reload, to replace the config with ${env.WORKSPACE}.

Add a git hook to this job, and you get a self-updating Jenkins whenever you push to master. Neat!

Next step would be to write some groovy to do this. I would get rid of the curls, the auth token they need, and restrict the job/repo to just people that are Jenkins admins.

@timja
Copy link
Member

timja commented Jul 7, 2019

@vladfr you can post to reload-configuration-as-code from git and it'll reload on push to master, you could do the validation on PR and then rely on git hook on master?
https://github.com/jenkinsci/configuration-as-code-plugin#triggering-configuration-reload

@MohammadRahaman
Copy link

@timja @ewelinawilkosz @ndeloof
I am trying to reload yaml file programmatically which will configure openstack plugin and when i will change or update my yaml file which will automatically reflect on openstack plugin configuration - that's our goal!!
I can perform manually in Jenkins UI - Configuration as Code. I am using groovy and yaml combined. If you've any code (groovy) which will reload yaml file automatically and configured openstack plugin would be appreciated!!

@timja
Copy link
Member

timja commented Jul 31, 2019

There's a webhook or CLI call you can make:
https://github.com/jenkinsci/configuration-as-code-plugin#triggering-configuration-reload

@MohammadRahaman
Copy link

@timja
we are not using Jenkins CLI!! how our job is running - after pushing the code to github then github triggering build in jenkins server. after that build is done which is based on commit message then will select template which is going to create image (according to our configuration), from that image we launched instances (openstack cloud) which has to be configured openstack cloud based on our yaml file. So how to configure that yaml file which is going to configure openstack cloud. That's I want!! If my explanation is clear !!!

@timja
Copy link
Member

timja commented Aug 1, 2019

I think this will reload through groovy?
ConfigurationAsCode.get().configure()

@MohammadRahaman
Copy link

@timja
I applied this method and it's reloading, when I change the file name it doesn't configured the way i expected - means new file configuration doesn't reflect in configure system. Still previous file configuration are there and I need to change the new file path manually then it works (after running job) which I am not expecting!!!

@timja
Copy link
Member

timja commented Aug 2, 2019

@MohammadRahaman
Copy link

@timja @ewelinawilkosz
it doesn't reload configuration on the fly when running the code!!!

Our goal is reload yaml file on the fly which will reflect on OpenStack cloud configuration but I couldn't find any solution so far!!! I used groovy and yaml combined, and creating yaml file which will retrieve all images from OpenStack 4J Clouds what I got dynamically but when I try to reload that file on the fly to configure OpenStack cloud configuration it doesn't do anything!! It creates updated yaml file(whatever parameter i changed) but doesn't reload automatically!!!

@jetersen
Copy link
Member

jetersen commented Aug 2, 2019

@MohammadRahaman
Surely you can figure out how to poke a URL if you can figure out how to configure OpenStack cloud configuration.
It's fully documented here: https://github.com/jenkinsci/configuration-as-code-plugin#triggering-configuration-reload

Instead of being so demanding and excessive usage of exclamation marks.
Perhaps you could consider contributing to the problem/solution, thank you.

@MohammadRahaman
Copy link

@Casz
I am not able to post screen shot because I didn't receive any error message, as I said that it will run successfully and create yaml file and changing values but not uploading/reloading dynamically which is going to reflect openstack cloud configuration. As the same yaml file when i reload manually it changing the openstack cloud configuration. That's the issue I am struggling to solve it but I can't!

is there anyway can I apply this approach in Jenkins pipeline? When I used curl -X POST "JENKINS_URL:8080/reload-configuration-as-code/?casc-reload-token=32424324rdsadsa" i got an below error
image
Any suggestion please

@jetersen
Copy link
Member

jetersen commented Aug 2, 2019

curl is a linux command-line tool and has nothing to do with groovy.
I am sorry @MohammadRahaman I cannot help you.

@MohammadRahaman
Copy link

@Casz
yes, you are right and I know that but what I applied in groovy as below -

def proc = "curl -X POST "http://ip address:8080/reload-configuration-as-code/?casc-reload-token=jenkins auth token"".execute()
// cURL uses error output stream for progress output.
Thread.start { System.err << proc.err }
// Wait until cURL process finished and continue with the loop.
proc.waitFor()

@MohammadRahaman
Copy link

@ewelinawilkosz @timja
After applying lot of approaches what I found a solution like first time I need to setup file path in configuration as code manually(one time activity), after that when job run it will reload automatically and configure automatically as well , if file name not exist in configuration as code plugin it won't configure. So whenever or whatever modification is done belongs to that file it will reflect on configuration page. If need to change file name next time then need to reconfigure the file name again as before otherwise it won't work.
image

Any suggestions please

@ewelinawilkosz
Copy link
Contributor Author

but what is your question now @MohammadRahaman ?
how to set up the location of the file? of course you have to do it manually - how else the plugin is supposed to find it? :) you can use "Path or URL" field or use environment variable CASC_JENKINS_CONFIG- it is explained in README

@MohammadRahaman
Copy link

@ewelinawilkosz
I set up path use environment variable like this export CASC_JENKINS_CONFIG=/var/jenkins/casc_config

But i want something like without manual interaction - it's like when jenkins job run on the fly it will set up the path automatic using environment variable and configured as well(changing existing to new configuration) which I declared in scripts but it won't. So my understanding it won't support 100% automatically.

@ewelinawilkosz
Copy link
Contributor Author

I'm afraid we can't help much more - as far as I understand automatic reload of configuration is possible to achieve, you seem to be asking about changing the location of configuration file ("set up the path") and that is not the scope of that issue and I am not sure it is a crucial feature - anyone can disagree of course
I opened the issue a long time ago and knowing what I know now I am satisfied with the solution so I'm closing that one.

@EricSalemi
Copy link

The link for triggering-configuration-reload mentioned throughout this thread is invalid.

Corrected link is:

https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/docs/features/configurationReload.md

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

No branches or pull requests

10 participants