Coder Social home page Coder Social logo

pipeline-library's Introduction

Pipeline Global Library for ci.jenkins.io

icon pipeline library

This repository contains a series of steps and variables for use inside of the Jenkins project’s own Jenkins instance(s).

Check this description of available services.

Useful steps:

buildPlugin

Applies the appropriate defaults for building a Maven-based plugin project on Linux and Windows.

You are advised to be using a 2.x or newer parent POM.

Jenkinsfile
buildPlugin(
  useContainerAgent: true,
  configurations: [
    [platform: 'linux', jdk: 11],
    [platform: 'linux', jdk: 17],
    [platform: 'windows', jdk: 11],
])

Optional arguments

  • repo (default: null inherit from Multibranch) - custom Git repository to check out

  • useContainerAgent (default: false) - uses a Container agent instead of a Virtual Machine: usually faster to start and generates less costs for the project

    • Please note that the implementation of "containers" can be changed over time

  • failFast (default: true) - instruct Maven tests to fail fast

  • platforms (default: ['linux', 'windows']) - Labels matching platforms to execute the steps against in parallel

  • jdkVersions (default: [8]) - JDK version numbers, must match a version number jdk tool installed

  • jenkinsVersions: (default: [null]) - a matrix of Jenkins baseline versions to build/test against in parallel (null means default, only available for Maven projects)

  • configurations: An alternative way to specify platforms, jdkVersions and jenkinsVersions (that can not be combined with any of them).

  • useArtifactCachingProxy: (default: true) - if set to false, artifacts will not use one of the artifact caching proxy depending on the agent provider (Azure, DigitalOcean or AWS), and will directly use repo.jenkins-ci.org instead (discouraged as less reliable and consuming bandwidth)

    • Those options will run the build for all combinations of their values. While that is desirable in many cases, configurations permit to provide a specific combinations of label and java/jenkins versions to use

      buildPlugin(/*...*/, configurations: [
        [ platform: "linux", jdk: "11", jenkins: null ],
        [ platform: "windows", jdk: "11", jenkins: null ],
        [ platform: "linux", jdk: "17", jenkins: "2.400" ]
      ])
  • tests: (default: null) - a map of parameters to run tests during the build. The test results and the JaCoCo code coverage results are recorded after the build with the corresponding Jenkins plugins.

    • skip - If true, skip all the tests by setting the -skipTests profile. It will also skip FindBugs in modern Plugin POMs.

  • jacoco: (default: null) - a map of parameters to change the default configuration of the recordCoverage step of the Code Coverage Plugin. This step is called after a plugin build to record the code coverage results of JaCoCo. See recordCoverage step documentation for a list of available configuration parameters.

  • pit: (default: null) - a map of parameters to change the default configuration of the recordCoverage step of the Code Coverage Plugin. See recordCoverage step documentation for a list of available configuration parameters. Since running PIT is a time-consuming task, PIT is disabled by default. You need to enable it by setting the property skip to false as well.

  • spotbugs, checkstyle, pmd, cpd: (default: null) - a map of parameters to archive SpotBugs, CheckStyle, PMD, or CPD warnings, respectively (only available for Maven projects). These values can replace or amend the default configuration for the recordIssues step of the Warnings NG Plugin. See Warnings NG Plugin documentation for a list of available configuration parameters.

  • timeout: (default: 60) - the number of minutes for build timeout, cannot be bigger than 180, i.e. 3 hours.

Note
The recordIssues steps of the warnings plugin and the recordCoverage steps of the coverage plugin run on the first platform/jdkVersion,jenkinsVersion combination only. So in the example below it will run for linux/jdk11 but not on jdk17.

Usage:

Jenkinsfile
buildPlugin(platforms: ['linux'],
        jdkVersions: [11, 17],
        jacoco: [sourceCodeRetention: 'MODIFIED'],
        pit: [skip: false],
        checkstyle: [qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]],
        pmd: [trendChartType: 'TOOLS_ONLY', qualityGates: [[threshold: 1, type: 'NEW', unstable: true]]])

buildPluginWithGradle()

Builds a Jenkins plugin using Gradle. The implementation follows the standard build/test/archive pattern. The method targets compatibility with Gradle JPI Plugin, and it may not work for other use-cases.

Optional arguments

  • repo (default: null inherit from Multibranch) - custom Git repository to check out

  • failFast (default: true) - instruct the build to fail fast when one of the configurations fail

  • platforms (default: ['linux', 'windows']) - Labels matching platforms to execute the steps against in parallel

  • jdkVersions (default: [8]) - JDK version numbers, must match a version number jdk tool installed

  • configurations: An alternative way to specify platforms, jdkVersions (that can not be combined with any of them)

    • Those options will run the build for all combinations of their values. While that is desirable in many cases, configurations permit to provide a specific combinations of label and java/jenkins versions to use

      buildPluginWithGradle(/*...*/, configurations: [
        [ platform: "linux", jdk: "8" ],
        [ platform: "windows", jdk: "8"],
      ])
  • tests: (default: null) - a map of parameters to run tests during the build

    • skip - If true, skip all the tests.

  • jacoco: (default: null) - a map of parameters to change the default configuration of the recordCoverage step of the Code Coverage Plugin. This step is called after a plugin build to record the code coverage results of JaCoCo. See recordCoverage step documentation for a list of available configuration parameters.

  • spotbugs, checkstyle: (default: null) - a map of parameters to archive SpotBugs or CheckStyle warnings, respectively. These values can replace or amend the default configuration for the recordIssues step of the Warnings NG Plugin. See Warnings NG Plugin documentation for a list of available configuration parameters.

  • timeout: (default: 60) - the number of minutes for build timeout, cannot be bigger than 180, i.e. 3 hours.

  • noIncrementals: (default: false) - de-activates incremental version publication.

Limitations

Not all features of buildPlugin() for Maven are supported in the gradle flow. Examples of not supported features:

  • Configuring jenkinsVersion for the build flow (as standalone arguments or as configurations)

  • Usage of Azure Container Instances as agents (only Maven agents are configured)

infra.isTrusted()

Determine whether the Pipeline is executing in an internal "trusted" Jenkins environment

Jenkinsfile
if (infra.isTrusted()) {
    /* perform some trusted action like a deployment */
}

infra.ensureInNode(nodeLabels, body)

Ensures that the given code block is runs in a node with the specified labels

Jenkinsfile
infra.ensureInNode('docker,java') {
    sh 'docker -v'
}

runBenchmarks

Runs JMH benchmarks and archives benchmark reports on highmem nodes.

Supported parameters:

artifacts

(Optional) If artifacts is not null, invokes archiveArtifacts with the given string value.

Example

runBenchmarks('jmh-report.json')

buildDockerAndPublishImage(imageName, config)

Lints, Builds, then publishes a docker image.

Adds a bunch of build args you can use in your docker image:

  • GIT_COMMIT_REV - The commit that triggered this build

  • GIT_SCM_URL - Url to repo

  • BUILD_DATE - Date that the image was built (now)

Supported parameters:

imageName

Name of the docker image to build

configs

(Optional) extra flags

registry: override the smart default of jenkinsciinfra/ or jenkins4eval/ dockerfile: override the default dockerfile of Dockerfile

Example

buildDockerImage_k8s('plugins-site-api')

Contribute

Requirements

  • (Open)JDK v8

  • Maven 3.6.x

===

pipeline-library's People

Contributors

dduportal avatar updatecli-gha-in-jenkins-infra-org[bot] avatar oleg-nenashev avatar dependabot[bot] avatar jglick avatar lemeurherve avatar raul-arabaolaza avatar v1v avatar lemeurhervecb avatar olblak avatar github-actions[bot] avatar basil avatar timja avatar halkeye avatar mramonleon avatar slide avatar jenkins-infra-bot avatar garethjevans avatar markewaite avatar smerle33 avatar darxriggs avatar olivergondza avatar daniel-beck avatar uhafner avatar notmyfault avatar rtyler avatar rsandell avatar abhyudayasharma avatar alecharp avatar batmat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.