All Products
Search
Document Center

Function Compute:Use a YAML file to describe a pipeline

Last Updated:Jan 11, 2025

A YAML file is instrumental in defining the execution of a pipeline within the Serverless Application Center, enabling the build and publication of serverless applications. This topic explains how to configure a YAML file and describes its predefined fields.

Background information

The YAML configuration file specifies the data structures for the pipeline and pipeline template objects, which are essential for task execution. A webhook triggers the application center when code repository changes occur, initiating the configured pipeline actions.

It is a recommended DevOps practice to use a configuration file to delineate pipeline operations in the application center. You may either specify an existing YAML file or create a new one during the application setup phase or within an environment. For more information, see Manage pipelines.

Prerequisites

  • You should be familiar with the concepts of pipelines and pipeline templates. For more information, see Pipeline and Pipeline template.

  • Ensure the creation of a Git repository compatible with the Serverless Application Center, and that you have the necessary management permissions. Alternatively, you can use the Git repository initialized during application creation in the Serverless Application Center.

  • Create a YAML configuration file in the root directory of your Git repository. This topic references the cicd.yaml file as an example.

Configure a YAML file

You can detail the pipeline's description, the associated pipeline template, and the execution method in a YAML file (recommended). Below is an illustrative example.

---
# Submit the pipeline for execution
kind: Pipeline
# The name of the pipeline must be globally unique. It is recommended to use commitID and timestamp to construct a unique name
name: "p-<% .git.shortCommitId %>-<% .currentTimestampMs %>"
# Configure the description
description: 'demo pipeline'
spec:
  context:
    data:
      ## Global DingTalk notification configurations. The configurations overwrite those in the template
      #dingdingNotification:
      #  # Disable the global DingTalk notification. You can enable DingTalk notification in subsequent processes
      #  enable: false
      #  # Skip notification when the task is executed successfully
      #  skipOnSuccess: false
      #  # Configure webhook settings for the DingTalk notification
      #  webhook: https://oapi.dingtalk.com/robot/send?access_token=xxx
      #  # The signature key for DingTalk notification
      #  secret: xxx
      #  # The content of the DingTalk notification. Do not configure text uniformly unless the purpose is to unify the content of the notification
      #  message:
      #    at:
      #      isAtAll: false
      #      atUserIds: ["admin"]
      #      atMobiles: ["188xxxx8888"]
      #    msgtype: text
      #    # Template syntax can be used in the text. A template can obtain the current execution status and exception information
      #    text: |
      #      task finished.
      #      TaskName: {{ .currentTask.name }}
      #      Success: {{ .success }}
      #      Status: {{ .currentTask.status.phase }}
      # Use Serverless Devs to deploy the application. Specify the location of the s.yaml file. The content is automatically provided when the pipeline is triggered
      # deployFile: s.yaml
      # Specify the name of the application. The name is automatically provided when the pipeline is triggered
      appName: <% .appName %>
      # The location of the s.yaml file in the repository. Here it refers to the s.yaml file in the root path
      deployFile: s.yaml
  # The pipeline template description used in this execution. Serverless Application Center supports built-in template descriptions in pipelines
  templateSpec:
    tasks:
    - name: pre-check
      context:
        data:
          displayName: "Pre-build check"
          enable: true
          steps:
            - plugin: "@serverless-cd/checkout"
            - plguin: "@serverless-cd/s-setup"
            - run: s plan -t "${{ ctx.data.deployFile }}"
      taskTemplate: serverless-runner-task
      runAfters: []
    - name: pre-check-approval
      context:
        data:
          displayName: "Manual review"
          enable: true
      taskTemplate: need-approval
      runAfters:
      - name: pre-check
    - name: build-and-deploy
      context:
        data:
          displayName: "Build and deploy"
          enable: true
          steps:
            - plugin: "@serverless-cd/checkout"
            - plugin: "@serverless-cd/s-setup"
            - run: s deploy -t "${{ ctx.data.deployFile }}" --use-local --assume-yes --skip-push
      taskTemplate: serverless-runner-task
      runAfters: 
      - name: pre-check-approval
        
---

In the provided example, a pipeline named p-<% .git.shortCommitId %>-<% .currentTimestampMs %> is created in response to a qualifying Git event. It sequentially executes three tasks: a pre-build check, a manual review, and the build and deployment process. Each task employs pipeline plugins and shell commands to define its specific execution steps.

Predefined variables in a YAML file

Serverless Application Center provides a set of predefined variables. When a pipeline is activated, these placeholders in the YAML file are substituted with the actual variable values, resulting in the commitment of the described pipeline and task objects.

Name

Description

Example

<% .appName %>

The name of the application.

headless-ffmpeg-wcha

<% .accountId %>

The ID of your Alibaba Cloud account.

143199913651****

<% .releaseVersion %>

The deployment version of the current pipeline.

1676913428****

<% .envName %>

The environment in which the current pipeline resides.

staging

<% .git.branch %>

The branch in which the current pipeline resides.

test

<% .git.commitId %>

The CommitId of the HEAD commit in this Git operation.

3b6b823cea88c356b10442580da5a02cde4****

<% .git.shortCommitId %>

The first seven characters of the CommitId of the HEAD commit in this Git operation.

3b6b823

<% .git.commitMessage %>

The message content of the HEAD commit in this Git operation.

update .s file

<% .git.tag %>

The tag name in this Git operation (if a tag exists).

dev

<% .git.author %>

The author of this Git operation.

developer

<% .git.action %>

The name of the action in this Git operation.

push

<% .currentTimestampMs %>

The timestamp when the deployment is executed. Unit: milliseconds.

1676971965781

<% .currentTimestampS %>

The timestamp when the deployment is executed. Unit: seconds.

1676971891

<% .randomString6 %>

A random six-character string.

abcdef