WEBBOOK CHAPTER

CI/CD, 서버실에서 클라우드까지: 12장. Declarative Jenkinsfile을 운영 가능하게 쓴다

12장. Declarative Jenkinsfile을 운영 가능하게 쓴다

Declarative Pipeline은 stage, post, environment, input을 읽기 쉽게 제한한다. complex Groovy를 pipeline 안에 늘리기보다 versioned script나 shared library로 꺼낸다. Jenkins Pipeline syntax의 실제 설치 plugin 버전을 controller의 snippet generator와 대조한다.


stage('Production approval') {
  when { branch 'main' }
  input { message 'Promote the verified digest?'; ok 'Promote' }
  steps { sh './deploy --digest "$ARTIFACT_DIGEST" --env production' }
}

shell interpolation에서 secret이 command line이나 log에 노출되지 않게 한다. 승인 뒤 agent를 오래 점유하지 않도록 input 위치를 설계한다. restart from stage가 이전 artifact를 재사용하는지, workspace 재build를 하는지 확인한다.