9.젠킨스 파이프라인 작성
1. 파이프라인을 작성할 수 있는 위치로 이동
→ Jenkins 메인 페이지 좌측 상단 → 새로운 Item
1-1. item 이름
my-first-pipeline
옵션
두 번째 탭의 Pipeline 선택
→ OK
2.파이프라인 작성 문법
기본 파이프라인 형태
파이프라인 스크립트
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}2-1. pipeline 문법
agent
파이프라인에 작성된 스크립트를 실행하는 역할이 누구인지 지정
agent any → 누구나 실행 가능
stages
실행될 모든 Job들의 집합
stage
하나의 Job, Job은 여러 개의 step으로 구성됨
steps
실제로 동작시킬 때 사용할 코드
좌측 지금 빌드(Build now)로 파이프라인 실행
3. Github repo에서 프로젝트를 Clone하기 위한 파이프라인 구성
3-1. 기본 파이프라인 샘플 코드 찾기
pipeline syntax → snippet generate → git:Git 선택
Repository URL
https:// github repository url 지정
→ 에러가 발생해도 무시
Branch
main
Crendentials
username & password로 생성한 credential 추가
Generate Pipeline Script 버튼 선택
3-1. 아래처럼 생성된 스크립트 복사 후 파이프라인 스크립트에 적용
스크립트 예시
파이프라인 스크립트
git branch: 'main', credentialsId: 'cred-with-username', url: 'https://github.com/devops-gugu/{repo 이름}'적용된 스크립트
파이프라인 스크립트
pipeline {
agent any
stages {
stage('Git clone') {
steps {
git branch: 'main', credentialsId: '2d9b9479-56a4-4267-836c-f2013112503e', url: 'https://github.com/guguttemy/first-jenkins-sample.git'
}
}
}
}
4. 지금 빌드(Build Now) 버튼을 통해 clone 명령어가 정상적으로 수행되는지 확인
에러가 발생할 경우 Build history에서 Console output 확인
docker 내부 접속
terminal
docker exec -it jenkins /bin/bash/ 경로 인지 확인
terminal
cd /목록 조회
terminal
ls경로 이동
terminal
cd /var/jenkins_home/workspace목록 조회
terminal
ls파이프라인 이름 확인
→ my-first-pipeline
해당 경로로 이동
terminal
cd my-first-pipeline해당 경로에 github repository 프로젝트 폴더가 clone 되었는지 확인
terminal
ls
# README.md build.gradle gradle gradlew ...Last updated on