Jenkins Pipeline Build Trigger with git pull, how?

I have a maven, java project and I am using git. I want to use jenkins to build + test + deploy (.war file) on a tomcat server (on the same device)

My current question is starting the build with pushing changes to the git repository wizard. However, he worked with the jenkins freestyle project. There, I could configure my git repository, so it detected any changes and started the build.

But as far as I can do my research using the "pipeline", it is best to start the process using the assembly + test + deploy. So I created a pipeline and wrote a jenkins file.

pipeline {
    agent any

    stages {
        stage('Compile Stage') {
            steps {
               withMaven(maven: 'maven_3_5_1'){
               bat 'mvn clean compile'
               }
            }
        }
        stage('Testing Stage') {
            steps {
                withMaven(maven: 'maven_3_5_1'){
                    bat 'mvn test'
                }
            }
        }
        stage('Deployment Stage (WAR)') {
            steps {
                withMaven(maven: 'maven_3_5_1'){
                    bat 'mvn deploy'
                }
            }
        }
    }
}

, git. jenkins git, .

, jenkins , git ( freestyle)?

.

+4
1

(Jenkinsfile)

Jenkinsfile .

, . Multibranch, Jenkins Git, , Jenkinsfile ( ). .

, SCM:

enter image description here

SCM:

enter image description here


( ), checkout , :

pipeline {
    agent any
    stages {
        stage('Compile Stage') {
            steps {
                checkout('https://git.example.com/repo.git')
                withMaven(maven: 'maven_3_5_1') {
                    bat 'mvn clean compile'
                }
            }
        }
// ...

(, ) .

, , :

enter image description here

, ( ): , , (5 ). , currentBuild.changeSets , checkout. , , . ...

+2

Source: https://habr.com/ru/post/1690514/


All Articles