Skip to content

DriesVanHool/jenkins-custom-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins custome pipline

This repo describes how to setup a Jenkins job with a custome pipeline to a Github repository.

Project setup

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>

Pipline setup in Jenkins

  1. First create a new Item and select Pipeline.

alt text

  1. Preferably discard your builds. You can choose the maximum amount of builds.

alt text

  1. Fill in the url to your repository

alt text

  1. To schedual your builds use Poll SCM. In the example bellow the trigger is set to every 5 minutes

alt text

  1. 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.

alt text

You also need to specify your branch. In the case of Github this will be main.

After this you are ready to go.

About

How to create a jenkins custome pipline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages