Jenkinsfiles are a relatively new feature in the Jenkins world and they come in two varieties and syntaxes:
- Declarative
- Groovy DSL
The Groovy DSL is very flexible and powerful, but it also facilitates some anti-patterns, so in this recipe we're going to focus on the declarative-style Jenkinsfiles.
You will need a GitHub repository containing a codebase that can be built and tested. Given the sheer number of possible programming languages and build systems available, we will choose an arbitrary Java project using the popular Maven build system.
It will be sufficient to add a file called `Jenkinsfile` with these contents:
pipeline { agent any tools { maven 'Maven 3.3.9' jdk 'jdk8' } stages { stage ('Initialize') { steps { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" ''' } } stage ('Build') { steps { sh 'mvn -Dmaven.test.failure.ignore=true install...