Adding a Step¶
1. Create the step file¶
Add vars/<stepName>.groovy. The file must define a call(...) method — that's what Jenkins invokes when pipeline code calls stepName().
def call(Map config = [:]) {
// pipeline DSL is available here: sh, echo, error, fileExists, env, etc.
echo "running ${config.get('target', 'default')}"
}
2. Write the test¶
Add test/<StepName>Test.groovy extending BasePipelineTest. Mock every DSL method the step calls via helper.registerAllowedMethod.
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import static org.junit.jupiter.api.Assertions.*
class MyStepTest extends BasePipelineTest {
@BeforeEach
void setUp() {
super.setUp()
binding.setVariable('env', [:])
}
@Test
void 'does the thing'() {
def script = loadScript('vars/myStep.groovy')
script.call()
// assert via helper.callStack, return values, or thrown exceptions
}
}
Dots in test method names
Java 25 rejects method names containing .. Never include filenames or extensions
in a test method name — use underscores instead (package_json not package.json).
3. Run the tests¶
4. Document the step¶
Add docs/steps/<step-name>.md and register it in mkdocs.yml under the Steps nav entry.