Automation Pipelines에서 파이프라인을 코드로 활용하는 방법
Automation Pipelines
에서 파이프라인을 코드로 활용하는 방법
DevOps 관리자 또는 개발자는 사용자 인터페이스를 사용하는 대신 YAML 코드를 사용하여
Automation Pipelines
에서 파이프라인을 생성하려고 할 수 있습니다. 파이프라인을 코드로 생성하면 코드 편집기를 사용하여 파이프라인 코드에 주석을 삽입할 수 있습니다.
- 코드 편집기가 있는지 확인합니다.
- 소스 제어 저장소에 파이프라인 코드를 저장하려는 경우 작업 인스턴스에 액세스할 수 있는지 확인합니다.
파이프라인 코드에서 환경 변수 및 보안 자격 증명과 같은 외부 구성을 참조할 수 있습니다. 파이프라인 코드에서 사용하는 변수를 업데이트할 때 파이프라인 코드를 업데이트하지 않고 변수를 업데이트할 수 있습니다.
파이프라인 YAML 코드를 템플릿으로 사용하여 다른 파이프라인을 복제 및 생성하고 템플릿을 다른 사용자와 공유할 수 있습니다.
소스 제어 저장소에 파이프라인 코드 템플릿을 저장할 수 있고 이를 통해 버전을 관리하고 업데이트를 추적할 수 있습니다. 소스 제어 시스템을 사용하여 파이프라인 코드를 쉽게 백업하고 필요한 경우 복원할 수 있습니다.
- 코드 편집기에서 파일을 생성합니다.
- 샘플 파이프라인 코드를 복사하여 붙여 넣고 특정 파이프라인 요구 사항을 반영하도록 업데이트합니다.
- 파이프라인 코드에 끝점을 포함하려면 예제 끝점 코드를 복사하여 붙여 넣은 후 끝점을 반영하도록 업데이트합니다.파이프라인 업무 공간에서 Kubernetes API 끝점을 사용하는 경우Automation Pipelines은 CI(지속적 통합) 작업 또는 사용자 지정 작업을 실행하는 데 필요한 Kubernetes 리소스(예: ConfigMap, Secret 및 포드)를 생성합니다.Automation Pipelines은 NodePort를 사용하여 컨테이너와 통신합니다.Automation Pipelines파이프라인 업무 공간은 지속적 통합 작업 및 사용자 지정 작업을 위해 Docker 및 Kubernetes를 지원합니다.업무 공간 구성에 대한 자세한 내용은 파이프라인 작업 공간 구성에서 참조하십시오.
- 코드를 저장합니다.
- 파이프라인 코드를 저장하고 버전을 관리하려면 소스 제어 저장소에 해당 코드를 체크인합니다.
- 지속적 통합 및 전달 파이프라인을 생성하는 경우 Kubernetes YAML 파일을 가져와야 합니다.Kubernetes YAML 파일을 가져오려면 스마트 파이프라인 템플릿의 지속적 전달 영역에서 파일을 선택하고프로세스를 클릭합니다. 또는 API를 사용합니다.
코드 예를 사용하여 파이프라인과 끝점을 나타내는 YAML 코드를 생성했습니다.
파이프라인 및 끝점에 대한 YAML 코드 예
이 YAML 코드 예에는 파이프라인의
Automation Pipelines
기본 구축, 단계, 작업, 알림 등에 대한 업무 공간을 나타내는 섹션이 포함되어 있습니다. 지원되는 플러그인에 대한 코드 예는 끝점에 Automation Pipelines 연결 항목을 참조하십시오.
--- kind: PIPELINE name: myPipelineName tags: - tag1 - tag2 # Ready for execution enabled: false #Max number of concurrent executions concurrency: 10 #Input Properties input: input1: '30' input2: 'Hello' #Output Properties output: BuildNo: '${Dev.task1.buildNo}' Image: '${Dev.task1.image}' #Workspace Definition ciWorkspace: image: docker:maven-latest path: /var/tmp endpoint: my-k8s cache: - ~/.m2 # Starred Properties starred: input: input1 output: output1 # Stages in order of execution stageOrder: - Dev - QA - Prod # Task Definition Section stages: Dev: taskOrder: - Task1, Task6 - Task2 Long, Task Long Long - Task5 tasks: Task1: type: jenkins ignoreFailure: false preCondition: '' endpoints: jenkinsServer: myJenkins input: job: Add Two Numbers parameters: number1: 10 number2: 20 Task2: type: blah # repeats like Task1 above QA: taskOrder: - TaskA - TaskB tasks: TaskA: type: ssh ignoreFailure: false preCondition: '' input: host: x.y.z.w username: abcd password: ${var.mypassword} script: > echo "Hello, remote server" TaskB: type: blah # repeats like TaskA above # Notificatons Section notifications: email: - stage: Dev #optional ; if not found - use pipeline scope task: Task1 #optional; if not found use stage scope event: SUCCESS endpoint: default to: - user@yourcompany.com - abc@yourcompany.com subject: 'Pipeline ${name} has completed successfully' body: 'Pipeline ${name} has completed successfully' jira: - stage: QA #optional ; if not found - use pipeline scope task: TaskA #optional; if not found use stage scope event: FAILURE endpoint: myJiraServer issuetype: Bug project: Test assignee: abc summary: 'Pipeline ${name} has failed' description: |- Pipeline ${name} has failed Reason - ${resultsText} webhook: - stage: QA #optional ; if not found - use pipeline scope task: TaskB #optional; if not found use stage scope event: FAILURE agent: my-remote-agent url: 'http://www.abc.com' headers: #requestHeaders: '{"build_no":"123","header2":"456"}' Content-Type: application/json Accept: application/json payload: |- Pipeline ${name} has failed Reason - ${resultsJson} ---
이 YAML 코드는 Jenkins 끝점 예를 나타냅니다.
--- name: My-Jenkins tags: - My-Jenkins - Jenkins kind: ENDPOINT properties: offline: true pollInterval: 15.0 retryWaitSeconds: 60.0 retryCount: 5.0 url: http://urlname.yourcompany.com:8080 description: Jenkins test server type: your.jenkins:JenkinsServer isLocked: false ---
이 YAML 코드는 Kubernetes 끝점 예를 나타냅니다.
--- name: my-k8s tags: [ ] kind: ENDPOINT properties: kubernetesURL: https://urlname.examplelocation.amazonaws.com userName: admin password: encryptedpassword description: '' type: kubernetes:KubernetesServer isLocked: false ---
파이프라인을 실행하고 필요에 따라 조정을 수행합니다. 파이프라인을 실행하고 결과를 보는 방법 항목을 참조하십시오.