Search code examples
jenkinsjenkins-pipelinecloudbees

How to test Jenkinsfile


I am trying to write the test cases to validate the Jenkinsfile, But the load script function not working expecting the extension to be provided and throwing ResourceException exception loadScript("Jenkinsfile")

Is their better way to test the Jenkinsfile


Solution

  • The problem is that there are not enough tools for the development of pipelines. Pipelines is DSL and it imposes a restrictions.

    There is an interesting approach to using flags. For example, test which defines outside pipeline(in job). If test=true, a pipeline change some "production" logic to "test" - select another agent, load artifacts into another repository, run another command and so on.

    But recently appeared Pipeline Unit Testing Framework. It allows you to unit test Pipelines and Shared Libraries before running them in full. It provides a mock execution environment where real Pipeline steps are replaced with mock objects that you can use to check for expected behavior.

    Useful links: