연동 및 테스트

nginx 빌드 파일 만들어서 간단하게 테스트하기 !


깃랩에 코드 넣기

1) branch 만들기

2) 도커 파일 생성

FROM ${harborIP}/jenkins/nginx:latest

COPY ./index.html /usr/share/nginx/html

EXPOSE 80

3) index.html 을 수정해서 붙혀넣게 끔 해두었음.


GitLab Access Token을 생성해서 젠킨스에 넣기

  • role 설정
  • scope 설정

젠킨스 깃 토큰 등록



젠킨스 파이프라인 코드

pipeline {
    agent any

    environment {
        registry= '${harbor IP}'
        port='${harbor Port}'
        imageName='jenkins/nginx'
        imageTag='latest'
    }
    stages {
        stage('git') {
            steps {
                git branch: 'main', credentialsId: 'gitlab', url: "http://${gitIP}/root/gittest.git"
            }

        }
        stage('Build') {
            steps {
                sh"""
                docker login --username=${harbor ID} --password=${harbor PW} ${harbor IP}
                docker images
                docker build --tag ${harbor IP}/jenkins/nginx:latest .
                docker images | grep nginx
                docker push ${harbor IP}/jenkins/nginx:latest
                """
            }

        }
    }
}

드디어 성공!


젠킨스 오류들

  • unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/jenkins_home/workspace/T1/Dockerfile: no such file or directory
    깃에 도커파일 이름 틀려서...
  • Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
    퍼미션 추가해버렸음..^^;;
  • /var/run/docker.sock:/var/run/docker.sock 여기에 설정 잘못해서 생긴 에러였음... sock에 정확하게 못붙어서 계속 생긴 오류들이였다.
    스택오버플로우0
    스택오버플로우1
    참고링크0
    참고링크1
    참고링크2
    참고링크3

profile
Are you nervous? Don't be

0개의 댓글

Powered by GraphCDN, the GraphQL CDN