hitcounter

What is it Jenkins?

Yet another post about jenkins ci/cd

Jenkins as CI/CD tool

Jenkins Logo

Jenkins offers a simple way to set up a continuous integration or continuous delivery environment for almost any combination of languages and source code repositories using pipelines, as well as automating other routine development tasks.

While Jenkins doesn’t eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself.

Tips and tricks

Getting list instaled plugins

Go to Jenkins script console (http(s)://JENKINS_URL/script) and execute script below


Jenkins.instance.pluginManager.plugins.each{
  plugin -> 
    println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")
}

As result you get list of a kind:

Name_of_the_plugin Short_name Version

If you want use list of plugins for auto installation, just modify previous script

Jenkins.instance.pluginManager.plugins.each{
  plugin -> 
    println ("${plugin.getShortName()}")
}


Jenkins delete failed build

Go to Jenkins script console (http(s)://JENKINS_URL/script) and execute script below


MAX_BUILDS = 2 // max builds to keep
 
def jobs = Jenkins.instance.items;
 
for (job in jobs) {
    println "Job: " + job.name
    def recent = job.builds.limit(MAX_BUILDS)
    println "Recent Builds: "  + recent
    println "============================="
    for (build in job.builds) {
        if (!recent.contains(build) && !build.isBuilding()) {
            println "Deleting: " + build
            build.delete()
            println ""
        }
    }
}

This script will delete failed build

Jenkins disable CSP (Content Security Policy)

If you want temporarily disable CSP. Go to Jenkins script console and execute command

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox allow-scripts; default-src 'self'; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline';")

If you want permanently disable CSP.

If you are running Jenkins on Ubuntu:


$ vim /etc/default/jenkins

Find the line with JAVA_ARGS and add the CSP policy like this: JAVA_ARGS="-Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src data:;\""

If you are running Jenkins on CentOS:


$ vim /etc/sysconfig/jenkins
Find the line with JENKINS_JAVA_OPTIONS and add the CSP policy like this: JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src data:;\""

After changes you should to restart Jenkins service

 
comments powered by Disqus