This is my test (copied from the snippets in the docs)
package vars
import org.junit.Before
import org.junit.Test
import com.lesfurets.jenkins.unit.declarative.*
class ExampleDeclarativePipelineTest extends DeclarativePipelineTest {
// Setup environment for running unit tests
@Override
@Before
public void setUp() throws Exception {
super.setUp();
}
@Test
public void should_execute_without_errors() throws Exception {
//def script = runScript("vars/exampleDeclarativePipeline.groovy")
def script = runScript("vars/Jenkinsfile")
assertJobStatusSuccess()
printCallStack()
}
}
That works if I have an actual Jenkinsfile, but I defined my pipeline in my shared library (common pattern at this point) and it looks like this:
def call(Map config) {
pipeline {
agent none
stages {
stage('Example Build') {
agent { docker 'maven:3-alpine' }
steps {
echo 'Hello, Maven'
sh 'mvn --version'
}
}
stage('Example Test') {
agent { docker 'openjdk:8-jre' }
steps {
echo 'Hello, JDK'
echo 'Hello, JDK'
echo 'Hello, JDK'
echo 'Hello, JDK'
echo 'Hello, JDK'
sh 'java -version'
}
}
}
}
}
If I point my test to this Groovy script (def script = runScript("vars/exampleDeclarativePipeline.groovy")) it seems to do nothing. It executes but I don't get a stack trace or anything (if it's a standard Jenkinsfile it works).
How can I test my shared pipeline code?
Wasn't sure if this was a bug so I opened one: https://github.com/jenkinsci/JenkinsPipelineUnit/issues/380