https://ojm1484.tistory.com/58 https://velog.io/@ss0510s/Jenkins-GitLab-연동#1-gitlab-access-token

docker exec -it jenkins(container id) bash

내부에 Gitlab 레포지토리 확인하려면

cd /var/jenkins_home/workspace/Hexagon 후 ls -a로 검색

pipeline 세팅

  1. 웹 세팅

I. Jenkins에서 new Item → Pipeline 하고 새로운 아이템 만들어준다.

II. Plugins 에서 Gitlab 별도로 설치해준다.

III. Build Triggers 에서 Build when a change is pushed to Gitlab에 있는

Gitlab Repository → Setting → Webhooks

  1. 코드
pipeline {
    agent any
    
    stages {
        stage('git-clone') {
            steps {
                // Git step to clone the repository
                git branch: 'master', credentialsId: 'jenkins', url: '<https://lab.ssafy.com/s11-fintech-finance-sub1/S11P21A106>'

                // Echo step to print a message
                echo 'clone-success'
            }
            post {
                success {
                    script {
                        def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
                        def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
                        mattermostSend(color: 'good',
                            message: "빌드 성공: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\\n(<${env.BUILD_URL}|Details>)",
                            endpoint: '<https://meeting.ssafy.com/hooks/ihqaf6pffbgefdd81h5713egce>',
                            channel: 'Jenkins_status'
                        )
                    }
                }
                failure {
                    script {
                        def Author_ID = sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
                        def Author_Name = sh(script: "git show -s --pretty=%ae", returnStdout: true).trim()
                        mattermostSend(color: 'danger',
                            message: "빌드 실패: ${env.JOB_NAME} #${env.BUILD_NUMBER} by ${Author_ID}(${Author_Name})\\n(<${env.BUILD_URL}|Details>)",
                            endpoint: '<https://meeting.ssafy.com/hooks/ihqaf6pffbgefdd81h5713egce>',
                            channel: 'Jenkins_status'
                        )
                    }
                }
            }
        }
    }
}