Container Infrastructure/Side Project_202108

16. Jenkins PipeLine 작성

11mia 2021. 8. 30. 02:46

1. credential 연결

git에서 access token 발급
범위는 repo, admin:repo_hook 선택

Jenkins 설정에서  GitHub Server정보 입력

Credential 정보 추가
연결에 성공했다

2. 파이프라인 생성

깃에서 아래의 간단한 프로젝트를 fork 뜨고 해당 프로젝트로 파이프라인을 만들어보고자한다

https://github.com/11mia/docker-hello-world

 

GitHub - 11mia/docker-hello-world: Node.js "Hello world"

Node.js "Hello world". Contribute to 11mia/docker-hello-world development by creating an account on GitHub.

github.com

우선, Jenkinsfile로 젠킨스 파이프라인을 작성한 후, 깃에 반영하였다. (git의 소스를 빌드까지만 하고, 배포까진 구현하지 못하였다)

pipeline {
    agent any

    stages {
        stage('git scm update') {
            steps {
                git url: 'https://github.com/11mia/docker-hello-world.git'
            }
        }
            
        stage('build'){
            steps {
                nodejs(nodeJSInstallationName: 'nodejs'){
                sh 'npm install'
                sh 'npm run'
                }
            }
        }
    }
}

파이프라인을 작성하기 위해 new item > pipeline 선택

git 정보와 5분간격으로 poll해오도록 크론을 걸어준다
git 정보 입력 후 git 내의 스크립트를 사용하도록 Script Path로 Jenkinsfile 및 체크박스를 체크해준다

Node.js 로 작성되었기 때문에 Node.js 플러그인 설치 및 Global Tool Configuration을 설정해준다

여러번의 실패 끝에 드디어 성공하였다

# 어디까지 했나

# 참고

https://cwal.tistory.com/21

 

CI를 위한 Jenkins, GitHub, Docker Hub 연계

본격적인 CI 구성을 위해 Jenkins와 GitHub 그리고 Docker Hub를 연계하는 방법에 대해 설명한다. k8s 위에 Jenkins를 배포하는 방법에 대해선 이전 포스트를 참고한다. 실습 환경에서 CI는 다음과 같은 일

cwal.tistory.com