- Add a task to a job
- Add a task to a job after a specific task
- Replace a resource definition in the pipeline YML
- Add email notifications to an existing pipeline
- Change the trigger flag of a job resource
- Additional operations samples
- Source YAML:
job.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
- task: first-task
file: task1.yml
- task: second-task
file: task2.yml
- Operations file:
add-task.yml
- op: add
path: /jobs/name=my-job/plan/-
value:
task: third-task
file: task3.yml
-
Execute yaml-patch command
cat job.yml | yaml-patch -o add-task.yml > result.yml
-
Resulting patched file:
result.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
- task: first-task
file: task1.yml
- task: second-task
file: task2.yml
- task: third-task
file: task3.yml
The combined use of the replace
operation from yaml-patch
with the do
tasks/resources grouping in Concourse pipelines allows you to "insert" tasks into the middle of the tasks of a job.
- Source YAML:
job-insert-task.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
- task: first-task
file: task1.yml
- task: last-task
file: taskn.yml
- Operations file:
insert-task.yml
- op: replace
path: /jobs/name=my-job/plan/task=first-task
value:
do:
- task: first-task
file: task1.yml
- task: second-task
file: task2.yml
-
Execute yaml-patch command
cat job-insert-task.yml | yaml-patch -o insert-task.yml > result.yml
-
Resulting patched file:
result.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
do:
- task: first-task
file: task1.yml
- task: second-task
file: task2.yml
- task: last-task
file: taskn.yml
The example below is similar to the resource replacement action done by pcf-pipelines in operations file use-pivnet-release.yml to use the pipelines release from PivNet instead of GitHub. When the resource name is updated, all the tasks that reference that name also need to be updated accordingly.
- Source YAML:
resource-entry.yml
---
resources:
- name: pcf-pipelines
type: git
source:
uri: git@github.com:pivotal-cf/pcf-pipelines.git
branch: master
private_key: ((git_private_key))
- Operations file:
replace-resource.yml
---
- op: replace
path: /resources/name=pcf-pipelines
value:
name: pcf-pipelines
type: pivnet
source:
api_token: "((pivnet_token))"
product_slug: pcf-automation
product_version: ~
-
Execute yaml-patch command
cat resource-entry.yml | yaml-patch -o replace-resource.yml > result.yml
-
Resulting patched file:
result.yml
---
resources:
- name: pcf-pipelines
type: pivnet
source:
api_token: "((pivnet_token))"
product_slug: pcf-automation
product_version: ~
For a sample on how to add email notification to all jobs of a pipeline (e.g. for upgrade-tile.yml), see add-email-nofication-to-upgrade-tile.yml.
The operations file injects entries to resource_types
and resources
arrays for the email resource and then adds email notification actions for success and failure scenarios to the pipeline jobs.
-
Source YAML: upgrade-tile.yml
-
Operations file: add-email-nofication-to-upgrade-tile.yml
-
Execute yaml-patch command
cat upgrade-tile.yml | yaml-patch -o add-email-nofication-to-upgrade-tile.yml > upgrade-tile-with-notifications.yml
-
Resulting patched file:
upgrade-tile-with-notifications.yml
For a sample on how to update the Trigger parameter for the apply-changes
job of the upgrade-tile.yml pipeline, see sample gated-apply-changes-job.yml.
- Source YAML:
job-trigger.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
trigger: true
- get: her-resource
trigger: true
- task: first-task
file: task1.yml
- Operations file:
replace-trigger.yml
- op: replace
path: /jobs/name=my-job/plan/get=my-resource/trigger
value: false
-
Execute yaml-patch command
cat job-trigger.yml | yaml-patch -o replace-trigger.yml > result.yml
-
Resulting patched file:
result.yml
---
jobs:
- name: my-job
plan:
- get: my-resource
trigger: false
- get: her-resource
trigger: true
- task: first-task
file: task1.yml
See operations for more examples of yaml-patch operations.