Open BarelElbaz opened 1 year ago
is this still an open issue for you?
Hey I have a kind of similar problem
I have a library in the following format
lib = library(identifier: 'jenkins@main', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/prudhvigodithi/opensearch-build-libraries.git',
]))
So inside the libraries repo https://github.com/prudhvigodithi/opensearch-build-libraries.git i have a library vars/gradleCheckFlakyTestChecker
that uses the code part of src/gradlecheck
in the same repo and I have the following jenkinsfile
lib = library(identifier: 'jenkins@main', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/prudhvigodithi/opensearch-build-libraries.git',
]))
pipeline {
agent { label 'testhost' }
options {
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '180'))
}
stages {
stage('Sample Stage') {
steps {
script {
gradleCheckFlakyTestChecker()
}
}
}
}
post() {
always {
script {
postCleanup()
}
}
}
}
The Jenkinsfile works and the job runs as expected. Now to test the pipeline and jenkinsfile I dont see a way to mock the classes part of src/gradlecheck
that is used by library gradleCheckFlakyTestChecker
part of jenkinsfile. This throws an error when tested as
super.testPipeline('jenkins/gradle/gradle-check-flaky-test-issue-creation.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/promotion/gradle-check-flaky-test-issue-creation.jenkinsfile')
Is there a way I can mock the external classes part of the gradleCheckFlakyTestChecker
when running the JenkinsPipelineUnit?
Describe your use-case which is not covered by existing documentation.
I'm trying to write unit test to my Jenkins shared library using jenkins-pipeline-unit but for no success.
My project/directory structure is:
I've initialized gradle and created some build.gradle file with many dependencies and tried to be accurate and use the plugins versions from my jenkins instance.
What I'm trying to do is to write test for automationTest.groovy variable.
here is some relevant code:
I need to test the value of the singleton JobData within the test file but have no idea how to import it
And this is the test that I'm trying to write:
My questions are: