本文介绍如何使用 Azure 开发人员 CLI (azd
) 为 azd
模板创建 GitHub Actions CI/CD 管道。 通过此管道,可以将模板更新推送到代码存储库,并自动预配更改并将其部署到 Azure 环境。
Note
该 azd pipeline config
命令处于 beta 阶段。 有关详细信息,请参阅 功能版本控制和发布策略。
Prerequisites
- 安装 Azure 开发人员 CLI
- Visual Studio Code (可选,用于编辑文件)
- 一个 GitHub 帐户
- Azure 订阅服务
初始化模板
此示例使用 Hello-AZD 模板,但你可以针对包含管道定义文件(通常位于azd
或.github
文件夹中)的任何.azdo
模板执行这些步骤。
在空目录中,初始化
hello-azd
模板:azd init -t hello-azd
出现提示时,输入环境的名称,例如 helloazd。
使用 GitHub Actions 创建管道
按照以下步骤创建和配置管道:
在模板根目录的终端中,运行:
azd pipeline config
当系统提示选择提供程序时,请选择 GitHub。
? Select a provider: [Use arrows to move, type to filter] > GitHub Azure DevOps
选择所需的 Azure 订阅和区域。
当系统提示配置远程存储库时,请选择 “创建新的专用 GitHub 存储库”。 如果有要使用的现有项目,还可以选择 “选择现有 GitHub 项目”。
? How would you like to configure your git remote to GitHub? [Use arrows to move, type to filter] Select an existing GitHub project > Create a new private GitHub repository Enter a remote URL directly
输入新存储库的名称。
当系统提示提交并推送本地更改以启动新的 GitHub Actions 运行时,请输入
y
。查看终端中的输出。 该
azd pipeline config
命令显示项目的 GitHub 存储库名称。Note
默认情况下,
azd pipeline config
会配置 OpenID Connect(OIDC),也称为 联盟 凭据。 若要改用客户端凭据,请运行azd pipeline config --auth-type client-credentials
。Terraform 不支持 OIDC/联合身份验证凭据。
在浏览器中,打开项目的 GitHub 存储库。
选择 操作 以查看工作流的运行情况。
通过代码更改来测试管道
在项目的
/src/components/pages
目录中,打开Home.razor
。在文件顶部附近找到
Hello AZD!
标题文本。将文本更改为
Hello, pipeline!
。保存文件。
提交并推送更改。 此操作将触发 GitHub Actions 流水线来部署更新。
在浏览器中,打开项目的 GitHub 存储库以查看:
- Your commit
- GitHub Actions 设置中的提交
选择 操作 以查看工作流程中显示的测试更新。
若要查看已部署的更新,请访问输出中
azd
提供的 Web 前端 URL。
使用azd
作为GitHub操作
可以将 azd
作为 GitHub 操作安装,使用 setup-azd action。 若要使用它,请将以下内容添加到 .github/workflows/azure-dev.yml
文件:
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install azd
uses: Azure/setup-azd@v1.0.0
Note
检查 setup-azd 版本 以获取最新的版本号。
清理资源
如果不再需要本文中创建的 Azure 资源,请运行以下命令:
azd down
此命令删除与项目关联的所有 Azure 资源。
Next steps
使用 Azure 开发人员 CLI (azd) 监视应用