Shared libraries
There are huge possibilities of jenkins usage. As the pipelines for various purposes grown in time, some of the pipelines code was repeating and that is where shared libraries become handy. Share library written in groovy is compiled and imported as dependency to any pipeline where needed.
Following main features are currently supported
Working with remote git repositories including the repo multiprojects (as it is in Android open source project)
Working with gerrit code review system
Building and verification of the projects
Notifications to gerrit review system and to communication channels about the verification results
Parametrization of the builds via UI (set your build/release parameters within UI template)
Automated changelog description for the releases
Static code analysis via SonarQube and CodeChecker
Vulnerabilities analysis via Mend
The particular features were split into several shared libraries logically by its purpose.
Public Jenkins shared library documentation: https://jenkins.io/doc/book/pipeline/shared-libraries/
Public Gerrit Trigger plugin documentation: https://plugins.jenkins.io/gerrit-trigger/
Adding shared library
Add the repository to your Jenkins instance as Shared library:
go to “Manage Jenkins” > “Configure System”
scroll down to “Global Pipeline Libraries” section
use “Add” and fill in the name of the library, default version and retrival method (Git is highly recommended):
Name: ci_scripts
Default version: master
Retrieval method → Modern SCM
Source Code Management → Git
Project Repository: ssh://gitea@gitea.amarulasolutions.com:38745/i-tools/ci_jenkins_lib.git
“Save”
The library can be loaded into every pipeline by selecting “Load implicitly”.
It is useful for testing to be able to change the version of the library (tag / branch). Select “Allow default version to be overridden” to enable this.
Importing shared library
By setting option ‘load implicitly’ to true, the library is loaded into the node automatically. To import the set version use:
import com.amarula.*
/* OR */
import com.amarula.build.Build
import com.amarula.deploy.Sftp
@Library('ci_scripts')
import com.amarula.*
Specific version of library can be loaded using ‘@<version>’. Version refers to tag, branch or commit id.
/* Using a version specifier, such as branch, tag, etc */
@Library('ci_scripts@devel')
import com.amarula.*