Giter VIP home page Giter VIP logo

Comments (4)

pteichner avatar pteichner commented on June 7, 2024
group 'com.****.jenkins.library'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'idea'

sourceCompatibility = 11
targetCompatibility = 11

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

sourceSets {
    main {
        groovy {
            srcDirs = ['src', 'vars']
        }
        resources {
            srcDir('resources')
        }
    }
    test {
        groovy {
            resources {
                srcDir('test')
            }
        }
    }
}

repositories {
    maven {
        url "***/maven-jenkins-release"
    }
    maven {
        url "***/maven-public"
    }
}

dependencies {
    // Jenkins core
    String JENKINS_VERSION = System.getenv('JENKINS_VERSION') ?: '2.303.3'
    String JENKINS_PIPELINE_UNIT_VERSION = "1.9"
    implementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: JENKINS_VERSION
    testImplementation group: 'org.jenkins-ci.main', name: 'jenkins-core', version: JENKINS_VERSION
    implementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION
    testCompileOnly group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.9.1"

    // Test frameworks
    //testImplementation group: "org.junit.vintage", name: "junit-vintage-engine", version: "5.9.1"
    //testCompileOnly group: 'junit', name: 'junit', version: '4.13.1'
    testImplementation group: 'junit', name: 'junit', version: '4.13.1'
    testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
    testImplementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION
    testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.5.13'
    implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.6'
    implementation group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: JENKINS_PIPELINE_UNIT_VERSION

    // Jenkins plugins
    implementation group: 'com.cloudbees', name: 'groovy-cps', version: '1.32'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.22', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-api', version: '2.40', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.83', ext: 'jar'
    implementation group: 'org.6wind.jenkins', name: 'lockable-resources', version: '2.12', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins', name: 'credentials', version: '2.6.1', ext: 'jar'

    // TRICKY: The lib folder contains all other plugins *JAR* files if not found in Maven
    //implementation fileTree(dir: 'lib', include: ['*.jar'])
}
test {
    include "**/**Test.class"
    useJUnit()

    testLogging {
        events "PASSED", "FAILED", "SKIPPED"
    }
    // delete old test reports
    dependsOn cleanTest

    // don't stop if tests fail
    ignoreFailures = true

    // minimize logging
    testLogging.maxGranularity = 0

    // show stdout from tests
    onOutput { dest, event -> print event.message }
    // show test results
    def results = []

    afterTest { desc, result ->
        println "${desc.className.split("\\.")[-1]}: " +
                "${desc.name}: ${result.resultType}"
    }

    afterSuite { desc, result ->
        if (desc.className) { results << result }
    }

    doLast {
        println "Tests: ${results.sum { it.testCount }}" +
                ", Failures: ${results.sum { it.failedTestCount }}" +
                ", Errors: ${results.sum { it.exceptions.size() }}" +
                ", Skipped: ${results.sum { it.skippedTestCount }}"
    }
}

from jenkinspipelineunit.

pteichner avatar pteichner commented on June 7, 2024

src/test/CreateBuildInfoDescriptionTest.groovy

import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Test

import static org.junit.Assert.assertEquals

class CreateBuildInfoDescriptionTest extends BasePipelineTest {
    def createBuildInfoDescription

    @Before
    void setUp() {
        super.setUp()
        // load toAlphanumeric
        createBuildInfoDescription = loadScript("vars/createBuildInfoDescription.groovy")
    }

    @Test
    void testCall() {
        // call toAlphanumeric and check result
        def asset = ["api":[version:"1"],"gui":[version:"2"]]
        def result = createBuildInfoDescription(asset)
        assertEquals("<ul><li>api: 1</li><li>gui: 2</li></ul>", result)
    }
}

from jenkinspipelineunit.

pteichner avatar pteichner commented on June 7, 2024

vars.createBuildInfoDescription.groovy

#!groovy

def call(artifacts) {
    def description = "<ul>"

    artifacts.each() {
        description += "<li>${it.key}: ${it.value.version}</li>"
    }
    description += "</ul>"
    return description.toString()
}

from jenkinspipelineunit.

nre-ableton avatar nre-ableton commented on June 7, 2024

I assume you mean "Gradle 7", since the latest Groovy version is 4.x. Anyways, I just merged a PR that updates to Gradle 8.x, please re-try and report back.

from jenkinspipelineunit.

Related Issues (20)

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.