This document describes how to configure tasks in Cloud Deploy. A task is a unit of work that can be used as a deploy hook , for deployment verification , for deploy analysis , or for a custom render or custom deploy in a custom target type .
You can configure a task on the delivery pipeline (as part of the strategy ) or the custom target type render or deploy.
With tasks, you can use system parameters by templating them into your task configuration.
Define a task
You can define a task in your delivery pipeline configuration or as part of a
custom target type definition. The following YAML shows the task
stanza used
in either case:
task
:
type
:
container
image
:
IMAGE
command
:
[
COMMANDS_TO_RUN
]
args
:
[
LIST_OF_ARGS
]
env
:
-
KEY1:VAL1
-
KEY2:VAL2
...
For the task
configuration:
-
typeSpecifies the kind of task being configured. Only
containeris supported. -
imageIs the path to the container image.
-
commandIs the command or commands to run on the container.
-
argsIs a collection of arguments to the
command. -
envIs a collection of environment variables to be provided to the running container.
System Parameters as task environment variables
Cloud Deploy offers system-generated parameters that you can use as
environment variables in your tasks, using the env
field in the container
task. The templated parameters can be present in
the key or value fields of an env
map entry.
Here are a couple of example use cases:
-
Passing in the Cloud Run service name, service URL, and revision name as environment variables.
task : type : container image : my-image command : [ "/bin/bash" ] env : - RUN_SERVICE_NAME : "${{ render.metadata.cloud_run.service.name }}" - RUN_SERVICE_URL : "${{ rollout.metadata.cloud_run.service_url }}" - RUN_REVISION_NAME : "${{ render.metadata.cloud_run.revision.name }}" -
Using multiple parameters in a single entry.
task : type : container image : my-image command : [ "/bin/bash" ] env : - DEPLOY_PARAMS_KEY : "${{ deploy_params['FOO'] }}-with-${{ deploy_params['BAR'] }}" - "${{ project.id }}_${{ location }}" : "${{ target.id }}"
Available system parameters
Cloud Deploy provides the following system parameters that you can use in your tasks configuration using this format:
${{ parameter }}
$${{ }}
.
The following is the list of parameters available for templating:
location
Available at release creation.
project.num
Available at release creation.
project.id
Available at release creation.
delivery_pipeline.name
Available at release creation.
delivery_pipeline.id
Available at release creation.
target.name
Available at release creation.
target.id
Available at release creation.
release.name
Available at release creation.
release.id
Available at release creation.
rollout.name
Available at rollout creation.
rollout.id
Available at rollout creation.
job.id
Available at rollout creation.
phase.id
job_run.name
Available at rollout creation.
job_run.id
Available at rollout creation.
deploy_params
Example:
deploy_params['KEY']
Trying to access a key that doesn't exist results in an empty string.
Available at release creation.
RUN
:cloud_run.project
Available at release creation.
cloud_run.location
Available at release creation.
render.metadata.cloud_run.service.name
Available after the render operation has completed.
render.metadata.cloud_run.service.id
Available after the render operation has completed.
rollout.metadata.cloud_run.service.url
Available after the deploy operation has completed.
render.metadata.cloud_run.revision.name
Available after the render operation has completed.
render.metadata.cloud_run.revision.id
Available after the render operation has completed.
rollout.metadata.cloud_run.previous_revision.name
Available after the deploy operation has completed.
rollout.metadata.cloud_run.previous_revision.id
Available after the deploy operation has completed.
GKE
:gke.cluster.name
Available at release creation.
gke.cluster.id
Available at release creation.
gke.cluster.project
Available at release creation.
gke.cluster.location
Available at release creation.
ANTHOS
:anthos.membership.project
Available at release creation.
anthos.membership.location
Available at release creation.
anthos.membership.name
Available at release creation.
anthos.membership.id
Available at release creation.
GKE
and ANTHOS
):render.metadata.kubernetes.deployment
Available after the render operation has completed.
render.metadata.kubernetes.canary_deployment
render.metadata.kubernetes.deployment
, because there is no
canary in the stable phase. For the other phases, this is the same as render.metadata.kubernetes.deployment
with -canary
on the end.Available after the render operation has completed.
render.metadata.kubernetes.namespace
Available after the render operation has completed.
CUSTOM_TARGET_TYPE
:render.metadata.custom
Example:
render.metadata.custom['KEY']
Trying to access a key that doesn't exist results in an empty string.
Available after the render operation has completed.
rollout.metadata.custom
Example:
rollout.metadata.custom['KEY']
Trying to access a key that doesn't exist results in an empty string.
Available after the deploy operation has completed.
Available environment variables
Cloud Deploy also provides and populates the following environment variables in the execution environment . You can use these environment variables as part of your deploy hook , verify job , or custom target render or deploy.
-
ANTHOS_MEMBERSHIPFor targets of type
ANTHOS, the fully specified resource name of the Anthos membership. -
CLOUD_RUN_LOCATIONFor targets of type
RUN, the region the Cloud Run service is deployed in. -
CLOUD_RUN_PROJECTFor targets of type
RUN, the project in which the Cloud Run service was created. -
CLOUD_RUN_SERVICEFor targets of type
RUN, the name of the Cloud Run service deployed. -
CLOUD_RUN_SERVICE_URLSFor targets of type
RUN, the URL or URLs (comma-separated list) that end users will use to access your service. You can find these in the Cloud Run service details for your service, in the Google Cloud console. The URLs are generated by Cloud Run after your Cloud Run Service or Services have been successfully deployed. Therefore this environment variable is only available in postdeploy hooks and verify jobs . -
CLOUD_RUN_REVISIONFor targets of type
RUN, the specific revision of the Cloud Run service. -
GKE_CLUSTERFor targets of type
GKE, the fully specified resource name of the Google Kubernetes Engine cluster, for exampleprojects/p/locations/us-central1/clusters/dev. -
TARGET_TYPEThe specific runtime type of the target. Either
GKE,ANTHOS, orRUN. For custom targets, this won't be set. -
CLOUD_DEPLOY_LOCATIONThe region containing the Cloud Deploy resources.
-
CLOUD_DEPLOY_DELIVERY_PIPELINEThe ID of the delivery pipeline.
-
CLOUD_DEPLOY_TARGETThe ID of the target.
-
CLOUD_DEPLOY_PROJECTThe Google Cloud project number for the project containing the Cloud Deploy resources.
-
CLOUD_DEPLOY_PROJECT_IDThe Google Cloud project ID for the project.
-
CLOUD_DEPLOY_RELEASEThe ID of the release in which the hooks will run.
-
CLOUD_DEPLOY_ROLLOUTThe ID of the rollout that contains the jobs for the hooks.
-
CLOUD_DEPLOY_JOB_RUNThe ID of the job run that represents the current execution of the job.
-
CLOUD_DEPLOY_PHASEThe phase in the rollout that contains the job for the deploy hook, verify job, or custom render or deploy.
What's next
- Learn how to run deploy hooks using tasks
- Learn how to verify your deployment using tasks
- Learn about custom targets

