script1
pipeline {
    agent any
    stages {
        stage('Compile') {
            steps {
                echo "Compiled successfully!";
            }
        }

        stage('JUnit') {
            steps {
                echo "JUnit passed successfully!";
            }
        }

        stage('Code Analysis') {
            steps {
                echo "Code Analysis completed successfully!";
            }
        }

        stage('Deploy') {
            steps {
                echo "Deployed successfully!";
            }
        }
    }
}

 

 

script2
pipeline {
    agent any
    stages {
        stage('Compile') {
            steps {
                echo "Compiled successfully!";
            }
        }

        stage('JUnit') {
            steps {
                echo "JUnit passed successfully!";
            }
        }

        stage('Code Analysis') {
            steps {
                echo "Code Analysis completed successfully!";
            }
        }

        stage('Deploy') {
            steps {
                echo "Deployed successfully!";
            }
        }
    }

    post {
      always {
        echo "This will always run"
      }
      success {
        echo "This will run when the run finished successfully"
      }
      failure {
        echo "This will run if failed"
      }
      unstable {
        echo "This will run when the run was marked as unstable"
      }
      changed {
        echo "This will run when the state of the pipeline has changed"
      }
    }
}

 

 

실습1

새 프로젝트 생성 시 Pipeline 선택

 

 

이름 기입

 

 

script1 기입

 

 

빌드 시 view 확인 가능

 

 

scripte2의 post 추가 입력

 

 

빌드 시 view 확인 가능

 

 

script3
pipeline {
    agent any
    stages {
        stage('Git clone') {
            steps {
                git branch: 'main', url: 'https://github.com/manupul/jenkins_pipeline_script'
            }
        }

        stage('Compile') {
            steps {
                echo "Compiled successfully!";
                sh './build.sh'
            }
        }

        stage('JUnit') {
            steps {
                echo "JUnit passed successfully!";
                sh './unit.sh'
            }
        }

        stage('Code Analysis') {
            steps {
                echo "Code Analysis completed successfully!";
                sh './quality.sh'
            }
        }

        stage('Deploy') {
            steps {
                echo "Deployed successfully!";
                sh './deploy.sh'
            }
        }
    }
}

 

 

실습2

새 repository 생성

 

 

파일 올리기

 

 

새 프로젝트 생성

 

 

설명 기입

 

 

빨간 박스 클릭

 

 

url 및 branch 기입

 

 

파란 박스 클릭 후 나오는 내용 복사

 

 

script3 넣은 후 git clone 주소 부분에 복사한 것으로 수정

 

 

빌드 시 모습

 

 

오류 메시지를 보니 허가권 문제였다

 

 

jenkins에 bash로 들어가서 확인해보자.

스크립트를 실행하기 위한 허가권이 없음

 

 

명령어 sh를 활용하면 실행됨

 

 

스크립트 수정

 

 

잘 실행 됨

 

 

post 부분을 뒤에 입력

 

 

빌드 성공

'docker' 카테고리의 다른 글

pipeline을 이용한 app 배포  (1) 2023.10.19
pipeline-view  (0) 2023.10.19
Docker hub를 이용한 container 생성  (0) 2023.10.18
ansible 내 tomcat SCM  (0) 2023.10.18
Ansible-server에 tomcat 생성  (1) 2023.10.17

+ Recent posts