DevOps 管理者または開発者は、ユーザー インターフェイスを使用するのではなく、YAML コードを使用して Automation Pipelines でパイプラインを作成することができます。パイプラインをコードとして作成する場合は、任意のエディタを使用して、パイプライン コードにコメントを挿入できます。
パイプライン コードでは、環境変数やセキュリティ認証情報などの外部構成を参照できます。パイプライン コードで使用する変数を更新する場合、パイプライン コードを更新せずに変数を更新できます。
パイプライン YAML コードをテンプレートとして使用して、他のパイプラインをクローン作成および作成し、テンプレートを他のユーザーと共有できます。
パイプライン コード テンプレートをソース管理リポジトリに保存して、バージョン管理と更新の追跡を行うことができます。ソース管理システムを使用すると、パイプライン コードのバックアップを簡単に作成し、必要に応じてリストアすることができます。
前提条件
- コード エディタがあることを確認します。
- ソース管理リポジトリにパイプライン コードを保存する場合は、作業インスタンスにアクセスできることを確認します。
手順
結果
コードの例を使用して、パイプラインとエンドポイントを表す 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 ---
次のタスク
パイプラインを実行し、必要に応じて調整します。パイプラインを実行して結果を確認する方法を参照してください。