This repo describes how to setup a Jenkins job with a custome pipeline to a Github repository.
Add a file named Jenkinsfile to your root directory with the following code.
pipeline {
agent any
tools {
maven 'Maven'
jdk 'jdk-17'
}
stages {
stage('Build') {
steps {
sh 'mvn clean install -DskipTests'
}
}
stage('jenkins-custom-pipeline') {
steps {
sh 'mvn -Dmaven.test.failure.ignore=true test'
}
}
}
post {
always {
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')]
junit 'target/surefire-reports/*.xml'
}
}
}
Add the correct maven plugins to your POM file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
- First create a new Item and select Pipeline.
- Preferably discard your builds. You can choose the maximum amount of builds.
- Fill in the url to your repository
- To schedual your builds use Poll SCM. In the example bellow the trigger is set to every 5 minutes
- After this set the Pipeline script from SCM (Git). To add credentials you have to create a token. This you can do via Github usersettings > Developer settings > Personal token.
You also need to specify your branch. In the case of Github this will be main.
After this you are ready to go.