Alex
Alex

Reputation: 2805

Backup and update Jenkins plugins via job, NOT manually

I'm hoping to create a Jenkins 2 pipeline job that will backup an image of the master node in aws, and then update any Jenkins plugins that need updating. The goal is to run this about once every 3-4 days when there's downtime to ensure everything is up to date, without needing to manually go through all the steps of logging into aws, making the backup, logging into jenkins and updating the plugins, etc.

After about an hour of research I'm no closer to finding even a partial solution for either of the two steps, so I'm reaching out to the community.

  1. Is it possible to build a pipeline job that backs up Jenkins in aws and if so, how?
  2. Can a Jenkins plugin update be triggered by a job, and if so, how?

I'd be shocked if neither of these can be done, but as a noob to Jenkins I'm struggling.

As an aside, I have seen/researched thinBackup but it doesn't seem to have the options I'm looking for. Please correct me if I'm wrong!

Upvotes: 1

Views: 697

Answers (2)

visit1985
visit1985

Reputation: 498

You can use the Scriptler Plugin to execute the following groovy script on Jenkins master from a Jenkins job.

import jenkins.model.Jenkins

def uc = Jenkins.instance.updateCenter
uc.updateAllSites()

uc.updates.each {
    print('Updating ' + it.title + ' Plugin from ' + it.installed.version + ' to ' + it.version + ' ...\n')
    it.deploy().get()
}

You can also schedule a save restart to activate the new plugin versions after you deployed them.

Jenkins.instance.safeRestart()

Upvotes: 2

jil
jil

Reputation: 2691

  1. To make a full backup you just need to copy $JENKINS_HOME directory. Should be doable in a shell step of a pipeline too.
  2. To update plugins you could just grab the latest hpi-file from the updates server and copy it into $JENKINS_HOME/plugins and then restart Jenkins. Alternatively you could use Groovy script to do it using Jenkins internal APIs.

Upvotes: 0

Related Questions