All Projects → mkobit → Jenkins Pipeline Shared Libraries Gradle Plugin

mkobit / Jenkins Pipeline Shared Libraries Gradle Plugin

Licence: mit
Gradle plugin to help with build and test of Jenkins Pipeline Shared Libraries (see https://jenkins.io/doc/book/pipeline/shared-libraries/)

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Jenkins Pipeline Shared Libraries Gradle Plugin

Hunter
A fast, incremental, concurrent framework to develop compile plugin for android project to manipulate bytecode
Stars: ✭ 999 (+869.9%)
Mutual labels:  gradle, gradle-plugin
Vertx Gradle Plugin
An opinionated Gradle plugin for Vert.x projects
Stars: ✭ 98 (-4.85%)
Mutual labels:  gradle, gradle-plugin
Enigma
Gradle Plugin - Obfuscator String Encryption (Android/Java)
Stars: ✭ 43 (-58.25%)
Mutual labels:  gradle, gradle-plugin
Plantuml Gradle Plugin
Gradle plugin to build PlantUML diagrams from code (for living and up-to-date documentation)
Stars: ✭ 27 (-73.79%)
Mutual labels:  gradle, gradle-plugin
Gradle Quality Plugin
Gradle quality plugin for Java and Groovy
Stars: ✭ 97 (-5.83%)
Mutual labels:  gradle, gradle-plugin
Gradle Defaults
Plugin providing opinionated defaults for Gradle projects.
Stars: ✭ 7 (-93.2%)
Mutual labels:  gradle, gradle-plugin
Gradle S3 Build Cache
An AWS S3 Gradle build cache implementation
Stars: ✭ 54 (-47.57%)
Mutual labels:  gradle, gradle-plugin
Let
Annotation based simple API flavored with AOP to handle new Android runtime permission model
Stars: ✭ 532 (+416.5%)
Mutual labels:  gradle, gradle-plugin
Androidanimationexercise
Android 动画各种实现,包括帧动画、补间动画和属性动画的总结分享
Stars: ✭ 1,254 (+1117.48%)
Mutual labels:  gradle, gradle-plugin
Gradle Plugins
Gradle Plugin Collection
Stars: ✭ 84 (-18.45%)
Mutual labels:  gradle, gradle-plugin
Ktlint Gradle
A ktlint gradle plugin
Stars: ✭ 713 (+592.23%)
Mutual labels:  gradle, gradle-plugin
Gradle Changelog Plugin
Plugin for parsing and managing the Changelog in a "keep a changelog" style.
Stars: ✭ 102 (-0.97%)
Mutual labels:  gradle, gradle-plugin
Gogradle
A Gradle Plugin Providing Full Support for Go
Stars: ✭ 712 (+591.26%)
Mutual labels:  gradle, gradle-plugin
Gradle Kotlin Aspectj Weaver
A Gradle plugin that allows you to weave your compiled Java and Kotlin files with AspectJ
Stars: ✭ 14 (-86.41%)
Mutual labels:  gradle, gradle-plugin
Gradle Git
Git plugin for Gradle
Stars: ✭ 559 (+442.72%)
Mutual labels:  gradle, gradle-plugin
Auto Manifest
Generates AndroidManifest.xml in simple libraries so that you don't have to
Stars: ✭ 51 (-50.49%)
Mutual labels:  gradle, gradle-plugin
Gradle Download Task
Adds a download task to Gradle that displays progress information
Stars: ✭ 478 (+364.08%)
Mutual labels:  gradle, gradle-plugin
Laziertracker
本项目通过Android字节码插桩插件实现Android端无埋点(或自动埋点),并且支持根据配置文件实现业务数据的自动采集。
Stars: ✭ 485 (+370.87%)
Mutual labels:  gradle, gradle-plugin
Gradle Semantic Build Versioning
Gradle plugin to generate version-numbers and tags using semantic versioning
Stars: ✭ 69 (-33.01%)
Mutual labels:  gradle, gradle-plugin
Gradle Buildconfig Plugin
A plugin for generating BuildConstants for any kind of Gradle projects: Java, Kotlin, Groovy, etc. Designed for KTS scripts.
Stars: ✭ 85 (-17.48%)
Mutual labels:  gradle, gradle-plugin

= Jenkins Pipeline Shared Library Gradle Plugin :toc: :supports-gradle: 5.0+ :github-repo-id: jenkins-pipeline-shared-libraries-gradle-plugin :uri-github-releases: https://github.com/mkobit/{github-repo-id}/releases :uri-jenkins-test-harness: https://github.com/jenkinsci/jenkins-test-harness.git :uri-jenkins-shared-library-docs: https://jenkins.io/doc/book/pipeline/shared-libraries/ :uri-jenkins-pipeline-unit: https://github.com/lesfurets/JenkinsPipelineUnit :uri-consumer-example: https://github.com/mkobit/jenkins-pipeline-shared-library-example :uri-build-status-image: https://circleci.com/gh/mkobit/{github-repo-id}/tree/master.svg?style=svg :circle-ci-status-badge: image:{uri-build-status-image}["CircleCI", link="https://circleci.com/gh/mkobit/{github-repo-id}/tree/master"] :uri-version-badge-image: https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/mkobit/jenkins/pipelines/jenkins-pipeline-shared-libraries-gradle-plugin/maven-metadata.xml.svg?label=Gradle Plugin Portal :uri-gradle-support-badge-image: https://img.shields.io/badge/Supports%20Gradle-{supports-gradle}-blue.svg :supports-gradle-badge: image:{uri-gradle-support-badge-image}["Gradle Version"] :uri-gradle-plugin-portal: https://plugins.gradle.org/plugin/com.mkobit.jenkins.pipelines.shared-library :uri-zenhub-badge: https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png :version-badge: image:{uri-version-badge-image}["Plugin Version", link="{uri-gradle-plugin-portal}"] :zenhub-badge: image:{uri-zenhub-badge}["ZenHub Badge", link="https://www.zenhub.com/"]

{circle-ci-status-badge} {version-badge} {supports-gradle-badge} {zenhub-badge}

NOTE: This documentation is for the HEAD of the repository. To see documentation at a specific version see the link:{uri-github-releases}[GitHub Releases page]

== Purpose

This plugin intends to help with development of link:{uri-jenkins-shared-library-docs}[Shared Libraries].

.Features

  • Basic Groovy compilation to validate source code
  • Unit test using link:{uri-jenkins-pipeline-unit}[Jenkins Pipeline Unit]
  • Usage of plugin and Jenkins core classes in library
  • @Grab support for libraries (testing limited to @JenkinsRule style integration tests due to link:https://stackoverflow.com/questions/4611230/no-suitable-classloader-found-for-grab[an issue])
  • @NonCPS annotation can be used in main source code
  • Source code generation to assist with development (for example, com.mkobit.jenkins.pipelines.codegen.LocalLibraryRetriever)
  • Integration test using the link:{uri-jenkins-test-harness}[Jenkins Test Harness]
  • Code completion in IDE

== Example Consumer

See the link:{uri-consumer-example}[example repository] for a demonstration of using this plugin.

== 5 minute onboarding

. Consume plugin from Gradle plugin portal + [source, kotlin]

plugins { id("com.mkobit.jenkins.pipelines.shared-library") version "x.x.x" }

. Set up preferred test dependencies (for example, JUnit or Spock) + [source, groovy]

repositories { jcenter() }

dependencies { testImplementation(group: 'junit', name: 'junit', version: '4.12') }

. Write some shared library code + .Library class - src/com/mkobit/LibHelper.groovy [source, groovy]

package com.mkobit

class LibHelper { private script LibHelper(script) { this.script = script }

void sayHelloTo(String name) { script.echo("LibHelper says hello to $name!") } }

.Global variable - vars/myGlobal.groovy [source, groovy]

def call() { echo 'Hello from myGlobal' }

. Write integration tests by utilizing a local JenkinsRule and setting up the shared library + .Integration tests - test/integration/groovy/com/mkobit/JenkinsGlobalLibraryUsageTest.groovy [source, groovy]

package com.mkobit

import com.mkobit.jenkins.pipelines.codegen.LocalLibraryRetriever import org.jenkinsci.plugins.workflow.libs.GlobalLibraries import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration import org.jenkinsci.plugins.workflow.libs.LibraryRetriever import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition import org.jenkinsci.plugins.workflow.job.WorkflowJob import org.jenkinsci.plugins.workflow.job.WorkflowRun import org.junit.Before import org.junit.Rule import org.junit.Test import org.jvnet.hudson.test.JenkinsRule

class JenkinsGlobalLibraryUsageTest {

@Rule public JenkinsRule rule = new JenkinsRule()

@Before void configureGlobalLibraries() { rule.timeout = 30 final LibraryRetriever retriever = new LocalLibraryRetriever() final LibraryConfiguration localLibrary = new LibraryConfiguration('testLibrary', retriever) localLibrary.implicit = true localLibrary.defaultVersion = 'unused' localLibrary.allowVersionOverride = false GlobalLibraries.get().setLibraries(Collections.singletonList(localLibrary)) }

@Test void testingMyLibrary() { CpsFlowDefinition flow = new CpsFlowDefinition(''' import com.mkobit.LibHelper

    final libHelper = new LibHelper(this)
    libHelper.sayHelloTo('mkobit')
'''.stripIndent(), true)
WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
workflowJob.definition = flow
WorkflowRun result = rule.buildAndAssertSuccess(workflowJob)
rule.assertLogContains('LibHelper says hello to mkobit!', result)

}

@Test void testingMyGlobalVar() { CpsFlowDefinition flow = new CpsFlowDefinition(''' import myGlobal

    myGlobal()
'''.stripIndent(), true)
WorkflowJob workflowJob = rule.createProject(WorkflowJob, 'project')
workflowJob.definition = flow
WorkflowRun result = rule.buildAndAssertSuccess(workflowJob)
rule.assertLogContains('Hello from myGlobal', result)

} }

== Configuring Versions

The sharedLibrary extension can be used to add additional plugin dependencies, Groovy version dependency, Jenkins Core dependency, etc. As of right now, most of the workflow-type plugins are automatically added based on default or configured versions. See the code for full details, but here is an example of what you can configure:

.Groovy build script - build.gradle [source, kotlin]

sharedLibrary { coreVersion = "2.86" testHarnessVersion = "2.24" pluginDependencies { workflowCpsGlobalLibraryPluginVersion = "2.8" dependency("io.jenkins.blueocean", "blueocean-web", "1.2.4") } }

NOTE: Due to link:https://github.com/gradle/kotlin-dsl/issues/380[kotlin-dsl/380], you will nee to use the .set methods instead of assignment. For example, coreVersion.set("2.86") is required.

== Limitations/Restrictions

=== Consuming the Gradle Configurations

There are several configurations that are created to group the different types of Jenkins dependencies used in this plugin. It is not recommended that you consume/extendsFrom these configurations as they may be changed underneath. It is instead recommended to use the configurations for each source set and make alterations to them (like link:https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSet.html#getImplementationConfigurationName--[`sourceSets.integrationTest.implementationConfigurationName`] and link:https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/SourceSet.html#getRuntimeOnlyConfigurationName--[`sourceSets.integrationTest.runtimeOnlyConfigurationName`]). If you have a specific use case please file an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].