티스토리 뷰

CI CD/JenKins

Jenkins(Mac m1) 18 Pipeline script

svdjcuwg4638 2023. 6. 30. 13:21

현재까지는 jenkins홈페이지에서 item을이용해서 빌드하고 배포를 하였지만

이제는 스크립트를 이용해서 다이나믹하게 빌드하고 배포를 해보도록하자

 

Declarative는 과정중 실패하게되면 더이상 진행하지않고

pipeline 안에 어떤 jenkins서버에 적용할것이인지 지정이 가능하고 현재 위 사진처럼

agent any라고 명시한것은 모든 jenkins서버에 허용하겠다는 뜻

stages에 실행할 스크립트를 작성해줌

 

Scripted는 진행중 실패하더라도 계속 진행하는 차이가있다.

 

스크립트로 성공했는지 실패했는지 등 확인여부를 판단하는 스크립트가 적용된 item을 생성해보자

 

Pipeline를 선택하고 생성

 

하단의 pipeline안에 밑과같이 작성합니다.

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!";
            }
        }
    }
}

 

pipeline로 시작해서 agent any로 모든 jenkins에 적용되도록 설정

저장하고 빌드하게되면

 

하단에 빌드 단계에 대한 결과를 확인할 수 있다.

console output에서도 밑과 같이 확인되는 모습

post를 추가해보자

    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"
      }
    }

구성에서 pipeline에 위코드를 stages밑에추가하여 실행해보자

post는 결과여부에따라 출력문이 달라지게된다. ex) 성공한다면 success의 echo가 보일것이다.

 

빌드시작 결과

 

post actino이 추가된것이 확인되고 

console output을 보니

script post문에 작성한 echo문을 확인

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함