This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.7.5.4. Jenkinsfile
jenkinsPipelineStrategy
를 사용하여 BuildConfig를 생성하면 인라인 jenkinsfile
을 사용하여 파이프라인에 수행할 작업을 지시합니다. 이 예에서는 애플리케이션에 대한 Git 리포지토리를 설정하지 않습니다.
다음 jenkinsfile
콘텐츠는 OpenShift DSL을 사용하여 Groovy로 작성됩니다. 소스 리포지토리에 jenkinsfile
을 포함하는 것이 기본 방법이지만 이 예제에서는 YAML 리터럴 스타일 을 사용하여 BuildConfig에 인라인 콘텐츠를 포함합니다.
완료된 BuildConfig는 예제 디렉터리 nodejs-sample-pipeline.yaml
의 OpenShift Origin 리포지토리에서 볼 수 있습니다.
def templatePath = 'https://raw.githubusercontent.com/openshift/nodejs-ex/master/openshift/templates/nodejs-mongodb.json' def templateName = 'nodejs-mongodb-example' pipeline { agent { node { label 'nodejs' } } options { timeout(time: 20, unit: 'MINUTES') } stages { stage('preamble') { steps { script { openshift.withCluster() { openshift.withProject() { echo "Using project: ${openshift.project()}" } } } } } stage('cleanup') { steps { script { openshift.withCluster() { openshift.withProject() { openshift.selector("all", [ template : templateName ]).delete() if (openshift.selector("secrets", templateName).exists()) { openshift.selector("secrets", templateName).delete() } } } } } } stage('create') { steps { script { openshift.withCluster() { openshift.withProject() { openshift.newApp(templatePath) } } } } } stage('build') { steps { script { openshift.withCluster() { openshift.withProject() { def builds = openshift.selector("bc", templateName).related('builds') timeout(5) { builds.untilEach(1) { return (it.object().status.phase == "Complete") } } } } } } } stage('deploy') { steps { script { openshift.withCluster() { openshift.withProject() { def rm = openshift.selector("dc", templateName).rollout().latest() timeout(5) { openshift.selector("dc", templateName).related('pods').untilEach(1) { return (it.object().status.phase == "Running") } } } } } } } stage('tag') { steps { script { openshift.withCluster() { openshift.withProject() { openshift.tag("${templateName}:latest", "${templateName}-staging:latest") } } } } } } }
def templatePath = 'https://raw.githubusercontent.com/openshift/nodejs-ex/master/openshift/templates/nodejs-mongodb.json'
def templateName = 'nodejs-mongodb-example'
pipeline {
agent {
node {
label 'nodejs'
}
}
options {
timeout(time: 20, unit: 'MINUTES')
}
stages {
stage('preamble') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
echo "Using project: ${openshift.project()}"
}
}
}
}
}
stage('cleanup') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.selector("all", [ template : templateName ]).delete()
if (openshift.selector("secrets", templateName).exists()) {
openshift.selector("secrets", templateName).delete()
}
}
}
}
}
}
stage('create') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.newApp(templatePath)
}
}
}
}
}
stage('build') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
def builds = openshift.selector("bc", templateName).related('builds')
timeout(5) {
builds.untilEach(1) {
return (it.object().status.phase == "Complete")
}
}
}
}
}
}
}
stage('deploy') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
def rm = openshift.selector("dc", templateName).rollout().latest()
timeout(5) {
openshift.selector("dc", templateName).related('pods').untilEach(1) {
return (it.object().status.phase == "Running")
}
}
}
}
}
}
}
stage('tag') {
steps {
script {
openshift.withCluster() {
openshift.withProject() {
openshift.tag("${templateName}:latest", "${templateName}-staging:latest")
}
}
}
}
}
}
}
- 1
- 사용할 템플릿의 경로입니다.
- 2
- 생성할 템플릿의 이름입니다.
- 3
- 이 빌드를 실행할
node.js
슬레이브 Pod를 실행합니다. - 4
- 이 파이프라인에 타임아웃을 20분으로 설정합니다.
- 5
- 이 템플릿 라벨이 있는 모든 항목을 삭제합니다.
- 6
- 이 템플릿 라벨을 사용하여 모든 보안을 삭제합니다.
- 7
templatePath
에서 새 애플리케이션을 생성합니다.- 8
- 빌드가 완료될 때까지 최대 5분 동안 기다립니다.
- 9
- 배포가 완료될 때까지 최대 5분 정도 기다립니다.
- 10
- 다른 모든 과정이 성공하면
$ {templateName}:latest
이미지에$ {templateName}-staging:latest
태그를 지정합니다. 스테이징 환경의 파이프라인 BuildConfig는$ {templateName}-staging:latest
이미지가 변경되고 스테이징 환경에 배포할 수 있습니다.
위 예제는 선언적 파이프라인 스타일을 사용하여 작성되었지만 오래된 스크립팅된 파이프라인 스타일도 지원됩니다.