来自 Azure DevOps 中不同存储库的 Cypress 管道
Cypress pipeline from different repo in Azure DevOps
我正在尝试将 Cypress 测试添加到 asp.net 应用程序。这是一个 .net 4.5 网站,我不确定如何将它添加到现有存储库中,因此我决定在同一个 Azure DevOps 项目中为它创建一个单独的存储库。所以我的 Azure DevOps 项目有两个存储库:一个用于 Web 应用程序,另一个用于 Cypress。
我需要创建一个 运行 管道,只要 Web 应用程序存储库的开发分支发生更改。它需要构建和 运行 来自 Web 应用程序存储库的单元测试,然后 运行 来自 Cypress 存储库的 Cypress 测试。
我很难把它放在一起。任何人都可以帮助创建执行这些任务的通用管道吗?可以帮助我弄清楚我需要走的方向的东西。
由于您想 运行 从您的 Web 应用程序管道中的另一个单独的存储库测试 Cypress,您必须从 Web 应用程序的 yaml 文件中检查 Cypress 存储库。
假设您的流水线没有阶段并且由多个作业组成,例如一个用于从您的 Web 应用程序执行任何操作,一个用于 Cypress 测试,这是一种可能的方法:
trigger:
- develop
resources:
repositories:
- repository: your-cypress-repo
type: git
name: your-azure-devops-project/your-cypress-repo
variables:
- group: cypress-variables
jobs:
- job:
# execute the unit tests or build of your web app here
- job: cypress_tests
displayName: 'Cypress Tests'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: your-cypress-repo
- task: NodeTool@0
inputs:
versionSpec: '14.x'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'Install Node.js'
- task: Npm@1
inputs:
command: 'ci'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'Execute npm clean-install'
- script: |
npm run {your package.json script for cypress test execution}
workingDirectory: $(Build.SourcesDirectory)
displayName: Cypress Tests
env:
CYPRESS_BASE_URL: '$(baseUrl)'
CYPRESS_someOtherEnvVariable: '$(someOtherEnvVariable)'
步骤简述:
- 触发器将是开发分支。
- 然后将必要的 Cypress 存储库定义为资源。
- 变量是可选的,但为赛普拉斯测试维护必要的秘密或凭据是有意义的,例如测试用户的密码,在管道定义之外可配置的变量组中。
- 我没有添加单元测试作业的详细信息,因为您可能已经知道了。 Cypress 测试的工作首先检查 Cypress 存储库(使用默认分支),安装 Node 和所有必需的包,最后执行您的 Cypress 测试。
作为提示,我还添加了如何将环境变量动态注入 Cypress 测试执行。这可以通过使用 CYPRESS_ 命名空间来完成,如 here.
所述
我正在尝试将 Cypress 测试添加到 asp.net 应用程序。这是一个 .net 4.5 网站,我不确定如何将它添加到现有存储库中,因此我决定在同一个 Azure DevOps 项目中为它创建一个单独的存储库。所以我的 Azure DevOps 项目有两个存储库:一个用于 Web 应用程序,另一个用于 Cypress。
我需要创建一个 运行 管道,只要 Web 应用程序存储库的开发分支发生更改。它需要构建和 运行 来自 Web 应用程序存储库的单元测试,然后 运行 来自 Cypress 存储库的 Cypress 测试。
我很难把它放在一起。任何人都可以帮助创建执行这些任务的通用管道吗?可以帮助我弄清楚我需要走的方向的东西。
由于您想 运行 从您的 Web 应用程序管道中的另一个单独的存储库测试 Cypress,您必须从 Web 应用程序的 yaml 文件中检查 Cypress 存储库。
假设您的流水线没有阶段并且由多个作业组成,例如一个用于从您的 Web 应用程序执行任何操作,一个用于 Cypress 测试,这是一种可能的方法:
trigger:
- develop
resources:
repositories:
- repository: your-cypress-repo
type: git
name: your-azure-devops-project/your-cypress-repo
variables:
- group: cypress-variables
jobs:
- job:
# execute the unit tests or build of your web app here
- job: cypress_tests
displayName: 'Cypress Tests'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: your-cypress-repo
- task: NodeTool@0
inputs:
versionSpec: '14.x'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'Install Node.js'
- task: Npm@1
inputs:
command: 'ci'
workingDirectory: $(Build.SourcesDirectory)
displayName: 'Execute npm clean-install'
- script: |
npm run {your package.json script for cypress test execution}
workingDirectory: $(Build.SourcesDirectory)
displayName: Cypress Tests
env:
CYPRESS_BASE_URL: '$(baseUrl)'
CYPRESS_someOtherEnvVariable: '$(someOtherEnvVariable)'
步骤简述:
- 触发器将是开发分支。
- 然后将必要的 Cypress 存储库定义为资源。
- 变量是可选的,但为赛普拉斯测试维护必要的秘密或凭据是有意义的,例如测试用户的密码,在管道定义之外可配置的变量组中。
- 我没有添加单元测试作业的详细信息,因为您可能已经知道了。 Cypress 测试的工作首先检查 Cypress 存储库(使用默认分支),安装 Node 和所有必需的包,最后执行您的 Cypress 测试。
作为提示,我还添加了如何将环境变量动态注入 Cypress 测试执行。这可以通过使用 CYPRESS_ 命名空间来完成,如 here.
所述