【问题标题】:Cypress can't find server when checking out repo in Azure DevOps pipeline在 Azure DevOps 管道中签出存储库时赛普拉斯找不到服务器
【发布时间】:2022-01-18 16:54:27
【问题描述】:

我有一个 Azure DevOps 项目,其中有 2 个存储库,一个带有 .net Web 应用程序,另一个带有 Cypress 测试。我需要创建一个管道,从 Web 应用程序存储库构建和运行单元测试,然后签出赛普拉斯存储库并运行 e2e 测试。当我的管道尝试运行赛普拉斯测试时,我收到错误消息“赛普拉斯无法验证此服务器是否正在运行:https://localhost:5001/”

我相信因为我的 cypress 测试位于不同的存储库中,所以我需要让我的 web 应用程序在服务器上运行,直到我的 cypress 测试完成。这个对吗?我不确定,所以这是一个猜测。我该如何设置才能让我的测试正常运行?

这是我的管道 yaml 文件:

trigger:
- development

resources:
 repositories:
   - repository: e2ecypress
     type: git
     name: devopsapp/e2ecypress

jobs:
  - job: build_unit_tests
    displayName: '.Net Build'

    pool:
      vmImage: 'windows-latest'

    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'

    steps:
    - task: NuGetToolInstaller@1

    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'

    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

  - job: cypress_tests
    displayName: 'Cypress Tests'
    pool:
      vmImage: 'windows-latest'
    
    steps:
    - checkout: e2ecypress

    - task: NodeTool@0
      inputs:
        versionSpec: '14.x'
      displayName: 'Install Node.js'
    
    - task: Npm@1
      inputs:
        command: 'install'
      displayName: 'NPM Install'
    
    - script: | 
        npx cypress run
      displayName: 'Cypress Tests'

这是我的管道运行的错误:

【问题讨论】:

  • 也许您可以在这里查看我对您之前的问题的评论:stackoverflow.com/a/70681905/6135684
  • @SebastianoVierk 我目前正在尝试这种方法。管道中的每个作业都会获得一个全新的虚拟机。这可能是我的问题吗?在我的应用程序构建之后,它会删除 vm,然后为 cypress 创建一个新的。我的 cypress 应用程序是否需要使用与 .net 作业相同的虚拟机?

标签: azure azure-devops continuous-integration azure-pipelines cypress


【解决方案1】:

一种可能的解决方案是在同一个作业中检查两个存储库,例如:

steps:
  - checkout: self
  - checkout: e2ecypress

关键字 self 指的是您从中执行管道的存储库,因此您的 Web 应用程序。但请注意,在签出多个存储库时,它们的目录路径会发生一些变化,请参阅 Docs:Check out multiple repositories in your pipeline

然后,您可以使用正确的路径访问 VM 中同一作业内的两个存储库中的内容。这允许您构建您的网络应用程序,启动它,然后在正在运行的应用程序上运行赛普拉斯测试。

要启动您的应用程序、运行测试并在完成后自动退出网络应用程序,您可以使用赛普拉斯也推荐的以下答案中描述的解决方案:https://stackoverflow.com/a/70541458/6135684

【讨论】:

  • 谢谢!这有很大帮助。我添加了结帐步骤,并且在运行命令和脚本时,我必须添加要指向的目录。所以:workingDir:e2ecypress
猜你喜欢
  • 1970-01-01
  • 2021-01-03
  • 1970-01-01
  • 2020-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多