Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jenkins Shared Libraries - Overview

Jenkins Shared Libraries - Overview

Let's discuss the Shared Libraries. What does it made for? What is a best practices to get onboard with the Libraries?

I'm going to tell you about 2 radically different Libraries, solving different tasks, and we will discuss the spirit and philosophy each of them. I believe it would be a good baseline to start with your own Library.

Nikolay Biryukov

November 08, 2018
Tweet

Other Decks in Programming

Transcript

  1. @Library() Code reuse Unification over a bunch of repos Credentials

    encapsulation Usability improvements Custom output Custom build configuration format
  2. 3 CODE REUSE Helpers def addDelimiter = { message ->

    lineLength = 80 line = “=“ * lineLength + “\n” return line + message.center(lineLength) + “\n” + line } def emailSuccess = { … } def emailFailure = { … }
  3. 4 CREDENTIALS ENCAPSULATION Public resources with shared credentials def promoteArtifact()

    { artifact, environment -> … } def gitClone() {} Environment provisioning def provisionCapacityTestEnv = { projectLabel -> … }
  4. 5 USABILITY IMPROVEMENTS General automation def unsealVault = { params.secKey1,

    params.secKey2 -> withCredentials ([ string(credentialsId: 'jenkinsKey', variable: ‘SECKEY3’) ]) { … }
  5. 6 USABILITY IMPROVEMENTS Popular common caveat #1 @Library(‘my-pretty-cool-lib@master’) _ 


    def version = ${param.libVersion} == null ? “master” : ${param.libVersion} def lib = (“my-cool-lib” + version).toString() library(lib)
  6. @Library(‘wolox-ci’) Language agnostic, initially written for RoR Lightweight TravisCI port

    to Jenkins :) Simple to get onboard Hard to propagate and support Out of the box connectors to Postgres, Redis, MongoDB
 ElasticSearch, MS Sql https://github.com/Wolox/wolox-ci
  7. 8 PAIN Pain cause #!/bin/bash +x set -e # Remove

    unnecessary files echo -e "\033[34mRemoving unnecessary files...\033[0m" rm -f log/*.log &> /dev/null || true &> /dev/null rm -rf public/uploads/* &> /dev/null || true &> /dev/null # Build Project echo -e "\033[34mBuilding Project...\033[0m" docker-compose --project-name=${JOB_NAME} build # Prepare test database COMMAND="bundle exec rake db:drop db:create db:migrate" echo -e "\033[34mRunning: $COMMAND\033[0m" docker-compose --project-name=${JOB_NAME} run \ -e RAILS_ENV=test web $COMMAND # Run tests COMMAND="bundle exec rspec spec" echo -e "\033[34mRunning: $COMMAND\033[0m" unbuffer docker-compose --project-name=${JOB_NAME} run web $COMMAND # Run rubocop lint COMMAND="bundle exec rubocop app spec -R --format simple" echo -e "\033[34mRunning: $COMMAND\033[0m" unbuffer docker-compose --project-name=${JOB_NAME} run -e RUBYOPT="-Ku" web $COMMAND
  8. 9 PAIN MITIGATOR Solution --- config: dockerfile: .woloxci/Dockerfile project_name: some-project-name

    services: - postgresql - redis steps: analysis: - bundle exec rubocop -R app spec --format simple - bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser setup_db: - bundle exec rails db:create - bundle exec rails db:schema:load test: - bundle exec rspec security: - bundle exec brakeman --exit-on-error audit: - bundle audit check --update environment: RAILS_ENV: test GIT_COMMITTER_NAME: a GIT_COMMITTER_EMAIL: b LANG: C.UTF-8
  9. @Library(‘wolox-ci’) PROS Simple to get onboard Good integration pattern Require

    minimal unsafe script approvals https://github.com/Wolox/wolox-ci CONS No YAML validation Dynamic step count visualization issue Shell-command style orientation No Windows/Powershell support
  10. @Library(‘wcm-io’) For Java/mvn projects with js/npm support Host deploy oriented

    (no containers support) Excellently documented Pretty interesting set of features Community-oriented (Adobe Experience Manager) Large number of installation https://github.com/wcm-io-devops/jenkins-pipeline-library
  11. 13 FEATURES Presumed infrastructure • jenkins.company.com - Jenkins Instance •

    git.company.com - Git Server • nexus.company.com - Sonatype Nexus artifact server • npm.company.com - NPM repository • bundler.company.com - Ruby bundler repository Concepts • Auto provide credentials (no worries, only Jenkins credential ids, not the credential itself) (see Credentials) • Auto provide maven settings (see ManagedFiles) • configure each job the same way (see ConfigStructure) • log and see the things you are interested in (see Logging)
  12. 14 FEATURES Extended Logging @Library ('pipeline-library') pipelineLibrary import io.wcm.devops.jenkins.pipeline.utils.logging.* Logger.init(steps,

    LogLevel.INFO) Logger log = new Logger(this) log.info("This is an info log from the pipeline library") [Pipeline] echo [INFO] WorkflowScript : This is an info log from the pipeline library [Pipeline] End of Pipeline Finished: SUCCESS
  13. 15 CONFIG Configuration example Map config = [ (SCM): [

    (SCM_URL): '[email protected]:group/project.git' ], (TOOLS): [ [ (TOOL_NAME): 'apache-maven3', (TOOL_TYPE): Tool.MAVEN ], [ (TOOL_NAME): 'jdk8', (TOOL_TYPE): Tool.JDK ] ], (MAVEN): [ (MAVEN_GOALS): [ "clean", "install" ] ], (LOGLEVEL): LogLevel.INFO ]
  14. @Library(‘wcm-io’) PROS Not very hard to get onboard Excellent documentation

    and tutorial Credentials auto-resolve HTTP, SSH, SCM Single configuration for Maven Extended Logging with colors Extended email notifications Custom SCP client https://github.com/wcm-io-devops/jenkins-pipeline-library CONS Require a lot unsafe script approvals Dynamic step count visualization issue Shell-command style orientation No Windows/Powershell support