Nas configurações de pipeline, use um arquivo .yaml para definir como o pipeline é executado no Serverless Application Center para compilar e publicar aplicações serverless. Este tópico descreve como configure um arquivo .yaml e os campos predefinidos nesse arquivo.
Contexto
Um arquivo .yaml descreve os objetos do pipeline e as estruturas de dados dos modelos usados na execução. Quando ocorre uma alteração em um repositório de código, o Serverless Application Center é acionado via webhook para executar pipelines com base no arquivo .yaml.
Recomendamos executar o pipeline com base em um arquivo .yaml, prática comum de DevOps no Serverless Application Center. Especifique um arquivo .yaml existente ou crie um novo ao criar uma aplicação ou ambiente. Para mais informações sobre como especifique um arquivo .yaml, consulte Gerenciar pipelines
Pré-requisitos
Familiarize-se com pipelines e modelos de pipeline. Para mais informações, consulte Pipeline e Modelo de pipeline
Crie um repositório git compatível com o Serverless Application Center e conceda as permissões de gerenciamento necessárias. Você também pode usar o repositório git criado e inicializado automaticamente durante a criação de aplicações no Serverless Application Center.
Crie um arquivo .yaml no diretório raiz do repositório git. Neste exemplo, usamos o arquivo cicd.yaml.
Configure um arquivo .yaml
Adicione a descrição do pipeline, o modelo referenciado ou o método de execução diretamente no arquivo .yaml. O código abaixo mostra um exemplo.
---
# Submit a pipeline for execution.
kind: Pipeline
# The name of the pipeline must be globally unique. We recommend that you use a commit ID and a timestamp to construct a name.
name: "p-<% .git.shortCommitId %>-<% .currentTimestampMs %>"
# Configure the description of the pipeline.
description: 'demo pipeline'
spec:
context:
data:
## Configure global DingTalk notifications. The configuration overwrites the notification settings in the template.
#dingdingNotification:
# # Disable global DingTalk notifications. You can enable DingTalk notification in subsequent tasks.
# enable: false
# # Skip notifications when the task is successfully executed.
# skipOnSuccess: false
# # Configure webhook settings for DingTalk notifications.
# webhook: https://oapi.dingtalk.com/robot/send?access_token=xxx
# # The signature key for DingTalk notifications.
# secret: xxx
# # The content of DingTalk notifications. Do not specify a fixed text unless you want to send only the fixed content.
# 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 exceptions.
# text: |
# task finished.
# TaskName: {{ .currentTask.name }}
# Success: {{ .success }}
# Status: {{ .currentTask.status.phase }}
# Use Serverless Devs to deploy the pipeline. Specify the location of the s.yaml file. The content is automatically populated when the pipeline is triggered.
# deployFile: s.yaml
# Specify the name of the application that you want to create in Serverless Application Center. The name is automatically provided when the pipeline is triggered.
appName: <% .appName %>
# The location of the s.yaml file in the repository. This s.yaml file is the one stored in the root path.
deployFile: s.yaml
# The description of the pipeline template that is used for execution. Serverless Application Center supports built-in template descriptions in pipelines.
templateSpec:
tasks:
- name: pre-check
context:
data:
displayName: "Pre-check"
enable: true
steps:
- plugin: "@serverless-cd/checkout"
- plugin: "@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: "Building and deployment"
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
---
No exemplo anterior, quando um evento git que atende a condições específicas ocorre, um pipeline nomeado no formato p-<% .git.shortCommitId %>-<% .currentTimestampMs %> é gerado. Consequentemente, três tarefas são executadas: pré-verificação, revisão manual e compilação com implantação. Em cada tarefa, plugins do pipeline e comandos shell descrevem etapas específicas de execução.
Variáveis predefinidas em um arquivo .yaml
A tabela a seguir lista as variáveis predefinidas fornecidas pelo Serverless Application Center. Ao acionar um pipeline, os placeholders no arquivo .yaml são substituídos pelos valores correspondentes das variáveis. Em seguida, os objetos do pipeline e das tarefas descritos no arquivo são enviados.
|
Variável |
Descrição |
Exemplo |
|
<% .appName %> |
Nome da aplicação. |
headless-ffmpeg-wcha |
|
<% .accountId %> |
ID da conta Alibaba Cloud. |
143199913651**** |
|
<% .releaseVersion %> |
Versão de implantação do pipeline. |
1676913428**** |
|
<% .envName %> |
Ambiente onde o pipeline reside. |
staging |
|
<% .git.branch %> |
Branch associada ao pipeline. |
test |
|
<% .git.commitId %> |
ID do commit HEAD nesta operação git. |
3b6b823cea88c356b10442580da5a02cde4**** |
|
<% .git.shortCommitId %> |
Primeiros sete caracteres do ID do commit HEAD na operação git. |
3b6b823 |
|
<% .git.commitMessage %> |
Mensagem do commit HEAD na operação git. |
update .s file |
|
<% .git.tag %> |
Nome da tag na operação git. Aplicável apenas se a tag existir. |
dev |
|
<% .git.author %> |
Autor da operação git. |
developer |
|
<% .git.action %> |
Nome da ação da operação git. |
push |
|
<% .currentTimestampMs %> |
Timestamp de início da consulta. Unidade: milissegundos. |
1676971965781 |
|
<% .currentTimestampS %> |
Timestamp de execução da implantação. Unidade: segundos. |
1676971891 |
|
<% .randomString6 %> |
String aleatória de 6 dígitos. |
abcdef |