Skip to content

Latest commit

 

History

History
 
 

03-integration-tests

jenkins-example-integration-tests

This example is based on the job-dsl project.

The integration tests ensure that Jenkins is running properly, they run some jobs and verify the console output.

How does it work?

  • Start Jenkins using the docker image.
  • Run integration tests, the tests uses the CLI client to access Jenkins. The tests consist on invoking groovy scripts on Jenkins and running jobs.
  • JenkinsInstanceSpec: Verify that Jenkins configuration is correct: Jenkins versions, installed plugins, deployed jobs, startup script executed.
  • RunJobSpec: Run some Jenkins jobs and verify that their console output is correct. Use existing jobs or create jobs on the fly using the DSL.

Integration test files

.
├── src/integration/groovy                                          # Integration tests
│   ├──  com.ticketfly.jenkins.common.JenkinsCLIWrapper             # Wrapper for the Jenkins CLI
│   ├──  com.ticketfly.jenkins.spec.JenkinsSpec                     # Base Specification
│   ├──  com.ticketfly.jenkins.spec.global.JenkinsInstanceSpec      # Test Jenkins configuration 
│   ├──  com.ticketfly.jenkins.spec.job.RunJobSpec                  # Test Jenkins jobs
└── build.gradle                                                    # define integration tasks

Quick start

  • ./gradlew runIntegration Build the docker image, start Jenkins, run integration tests, stop Jenkins.

  • ./gradlew integration Run integration tests. (Jenkins has to be started)

  • ./gradlew integration -Dintegration.single=JenkinsInstanceSpec Run a single spec.

  • curl -sSL "http://localhost:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'|sed 's/ /:/' | sort List plugin versions on running Jenkins.

Video Tutorials

Video: How to test Jenkins changes?

Why having integration tests for Jenkins?

They are many things that can go wrong when making some changes on the Jenkins docker image:

  • Version or plugin upgrade not backward compatible: unfortunately this is not uncommon with Jenkins and its plugin ecosystem. More generally, having integration tests will enable you to upgrade more frequently.
  • Error in DSL scripts. Integration tests can verify and run the jobs generated by the DSL, they would fail if the jobs were missing or are incorrect.
  • Error during startup script. Like any runtime scripts, the scripts located in init.groovy.d can be easy to break and hard to test. In this example, the startup script sets the markup formatter to be HTML. An integration verifies this, the test is called check configured markup is HTML.

Dockerhub

Hosted at ticketfly/jenkins-example-integration-tests

Requirements

  • Docker Version 1.10 or higher.

Resources